mirror of
https://github.com/XRPLF/rippled.git
synced 2026-09-26 15:10:12 +00:00
Compare commits
108 Commits
dangell7/d
...
mvadari/re
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1eab60b9cb | ||
|
|
ac794f695d | ||
|
|
d38f45701f | ||
|
|
b557403ab6 | ||
|
|
8c80a6aad5 | ||
|
|
9b1406ad46 | ||
|
|
6809690fad | ||
|
|
5b6e8b6f93 | ||
|
|
1306d35e4d | ||
|
|
028f0cb5da | ||
|
|
15b3ed1ae7 | ||
|
|
144835ca5d | ||
|
|
554c0baa0a | ||
|
|
cce4cfef10 | ||
|
|
7661483c4c | ||
|
|
6cb5842a05 | ||
|
|
bcd26397fb | ||
|
|
ffaf51043d | ||
|
|
cedebd5a86 | ||
|
|
700cd6a2b1 | ||
|
|
3d2e0788cc | ||
|
|
d7b6c8e098 | ||
|
|
d10bb71eea | ||
|
|
5dbbd9ba8d | ||
|
|
fb37cc2f42 | ||
|
|
fabf328485 | ||
|
|
dc2430ea86 | ||
|
|
0de37c2cad | ||
|
|
3d9eba73e8 | ||
|
|
dae0a53c20 | ||
|
|
ea3ca12894 | ||
|
|
7b27096aac | ||
|
|
c00491baa1 | ||
|
|
d616aff4e2 | ||
|
|
be9913f16f | ||
|
|
b99a7666ab | ||
|
|
683ff84ee0 | ||
|
|
9c9281e5d9 | ||
|
|
2d6450904d | ||
|
|
8269964c76 | ||
|
|
945b4f77cd | ||
|
|
03863d91ad | ||
|
|
737d128cca | ||
|
|
97629e7477 | ||
|
|
b0ca6adf7a | ||
|
|
e2238b13de | ||
|
|
27e9d0d695 | ||
|
|
b3829e5e61 | ||
|
|
50968111da | ||
|
|
fa77338bdc | ||
|
|
ffd96e354f | ||
|
|
e9287812ef | ||
|
|
819d3fcdfc | ||
|
|
dcdc5e1b52 | ||
|
|
c0895c6e2e | ||
|
|
5b0b1ff1f6 | ||
|
|
e9c4ed6a74 | ||
|
|
deaa23f4e5 | ||
|
|
638477c824 | ||
|
|
9b42e178a2 | ||
|
|
f41c02d486 | ||
|
|
a423813098 | ||
|
|
56c173a097 | ||
|
|
7900fa9ead | ||
|
|
0ffb3e2227 | ||
|
|
add3d7e68d | ||
|
|
c24432f43a | ||
|
|
1ccd84e43a | ||
|
|
1cc7424934 | ||
|
|
b5562cc81e | ||
|
|
e6369c0faa | ||
|
|
43caa7d47a | ||
|
|
e0f487bb2e | ||
|
|
a8987cf271 | ||
|
|
4157e3684c | ||
|
|
659f455335 | ||
|
|
3bc460951c | ||
|
|
d1dae53097 | ||
|
|
733dd51720 | ||
|
|
9d67db1843 | ||
|
|
29bb59698f | ||
|
|
3b2dcefb81 | ||
|
|
4e92ec2daf | ||
|
|
6afcf51dee | ||
|
|
7e62ecb63b | ||
|
|
ad2c359f21 | ||
|
|
96d4a69a37 | ||
|
|
14fbdd5a1c | ||
|
|
3c5e87888e | ||
|
|
8e218a6285 | ||
|
|
8a1adc4ec9 | ||
|
|
c9db124015 | ||
|
|
7056b43c5e | ||
|
|
ee370fefee | ||
|
|
e68d74cda4 | ||
|
|
89a3a6c379 | ||
|
|
f3a6d17b5b | ||
|
|
45531b1eaf | ||
|
|
fa8de2b47f | ||
|
|
6fcda8802e | ||
|
|
0cf42b150c | ||
|
|
74b010a905 | ||
|
|
265deccabe | ||
|
|
ea1146d413 | ||
|
|
5fa9bb53a8 | ||
|
|
d9bf263543 | ||
|
|
1f73da466c | ||
|
|
e9eb5e53c9 |
12
.clang-tidy
12
.clang-tidy
@@ -171,7 +171,7 @@ CheckOptions:
|
||||
readability-identifier-naming.EnumCase: CamelCase
|
||||
readability-identifier-naming.EnumConstantCase: CamelCase
|
||||
readability-identifier-naming.ScopedEnumConstantCase: CamelCase
|
||||
readability-identifier-naming.GlobalConstantCase: UPPER_CASE
|
||||
readability-identifier-naming.GlobalConstantCase: CamelCase
|
||||
readability-identifier-naming.GlobalConstantPrefix: "k"
|
||||
readability-identifier-naming.GlobalVariableCase: CamelCase
|
||||
readability-identifier-naming.GlobalVariablePrefix: "g"
|
||||
@@ -179,14 +179,12 @@ CheckOptions:
|
||||
readability-identifier-naming.ConstexprMethodCase: camelBack
|
||||
readability-identifier-naming.ClassMethodCase: camelBack
|
||||
readability-identifier-naming.ClassMemberCase: camelBack
|
||||
readability-identifier-naming.ClassConstantCase: UPPER_CASE
|
||||
readability-identifier-naming.ClassConstantCase: CamelCase
|
||||
readability-identifier-naming.ClassConstantPrefix: "k"
|
||||
readability-identifier-naming.StaticConstantCase: UPPER_CASE
|
||||
readability-identifier-naming.StaticConstantCase: CamelCase
|
||||
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.StaticVariableCase: camelBack
|
||||
readability-identifier-naming.ConstexprVariableCase: camelBack
|
||||
readability-identifier-naming.LocalConstantCase: camelBack
|
||||
readability-identifier-naming.LocalVariableCase: camelBack
|
||||
readability-identifier-naming.TemplateParameterCase: CamelCase
|
||||
|
||||
2
.github/scripts/rename/config.sh
vendored
2
.github/scripts/rename/config.sh
vendored
@@ -62,7 +62,7 @@ ${SED_COMMAND} -i 's@ripple/@xrpld/@g' src/test/core/Config_test.cpp
|
||||
${SED_COMMAND} -i 's/Rippled/File/g' src/test/core/Config_test.cpp
|
||||
|
||||
# Restore the old config file name in the code that maintains support for now.
|
||||
${SED_COMMAND} -i 's/kCONFIG_LEGACY_NAME = "xrpld.cfg"/kCONFIG_LEGACY_NAME = "rippled.cfg"/g' src/xrpld/core/detail/Config.cpp
|
||||
${SED_COMMAND} -i 's/kConfigLegacyName = "xrpld.cfg"/kConfigLegacyName = "rippled.cfg"/g' src/xrpld/core/detail/Config.cpp
|
||||
|
||||
# Restore an URL.
|
||||
${SED_COMMAND} -i 's/connect-your-xrpld-to-the-xrp-test-net.html/connect-your-rippled-to-the-xrp-test-net.html/g' cfg/xrpld-example.cfg
|
||||
|
||||
2
.github/scripts/rename/docs.sh
vendored
2
.github/scripts/rename/docs.sh
vendored
@@ -90,7 +90,7 @@ ${SED_COMMAND} -i 's/www.ripple.com/www.xrpl.org/g' src/test/protocol/Seed_test.
|
||||
# Restore specific changes.
|
||||
${SED_COMMAND} -i 's@b5efcc/src/xrpld@b5efcc/src/ripple@' include/xrpl/protocol/README.md
|
||||
${SED_COMMAND} -i 's/dbPrefix_ = "xrpldb"/dbPrefix_ = "rippledb"/' src/xrpld/app/misc/SHAMapStoreImp.h # cspell: disable-line
|
||||
${SED_COMMAND} -i 's/kCONFIG_LEGACY_NAME = "xrpld.cfg"/kCONFIG_LEGACY_NAME = "rippled.cfg"/' src/xrpld/core/detail/Config.cpp
|
||||
${SED_COMMAND} -i 's/kConfigLegacyName = "xrpld.cfg"/kConfigLegacyName = "rippled.cfg"/' src/xrpld/core/detail/Config.cpp
|
||||
|
||||
popd
|
||||
echo "Renaming complete."
|
||||
|
||||
2
.github/workflows/check-pr-title.yml
vendored
2
.github/workflows/check-pr-title.yml
vendored
@@ -11,4 +11,4 @@ on:
|
||||
jobs:
|
||||
check_title:
|
||||
if: ${{ github.event.pull_request.draft != true }}
|
||||
uses: XRPLF/actions/.github/workflows/check-pr-title.yml@a5d8dd35be543365e90a11358447130c8763871d
|
||||
uses: XRPLF/actions/.github/workflows/check-pr-title.yml@291206777251b4d493641b5afbdf7c23009d2988
|
||||
|
||||
2
.github/workflows/reusable-clang-tidy.yml
vendored
2
.github/workflows/reusable-clang-tidy.yml
vendored
@@ -176,7 +176,7 @@ jobs:
|
||||
|
||||
- name: Create issue
|
||||
if: ${{ steps.run_clang_tidy.outcome != 'success' && inputs.create_issue_on_failure }}
|
||||
uses: XRPLF/actions/create-issue@fbcc16eb7f20dc3199eaf1aed0d3523a5ba9008c
|
||||
uses: XRPLF/actions/create-issue@36d450d12d301e8410c1b7936e5de70c291cbe36
|
||||
with:
|
||||
title: "Clang-tidy check failed"
|
||||
body_file: ${{ env.ISSUE_FILE }}
|
||||
|
||||
@@ -527,6 +527,17 @@
|
||||
#
|
||||
# The current default (which is subject to change) is 300 seconds.
|
||||
#
|
||||
# verify_endpoints = <0 | 1>
|
||||
#
|
||||
# If set to 0, the server will skip validation of endpoint
|
||||
# addresses received in TMEndpoints peer protocol messages,
|
||||
# allowing addresses that are not publicly routable or have a
|
||||
# port of 0. The default is 1 (verification enabled).
|
||||
#
|
||||
# WARNING: Disabling this option is a security risk and should
|
||||
# only be used for local testing and debugging. Do not disable
|
||||
# on mainnet.
|
||||
#
|
||||
#
|
||||
# [transaction_queue] EXPERIMENTAL
|
||||
#
|
||||
|
||||
@@ -326,3 +326,4 @@ words:
|
||||
- xrplf
|
||||
- xxhash
|
||||
- xxhasher
|
||||
- CGNAT
|
||||
|
||||
@@ -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 kTAG_MASK = 1;
|
||||
static constexpr std::uintptr_t kPTR_MASK = ~kTAG_MASK;
|
||||
static constexpr std::uintptr_t kTagMask = 1;
|
||||
static constexpr std::uintptr_t kPtrMask = ~kTagMask;
|
||||
|
||||
private:
|
||||
/** Return the raw pointer held by this object.
|
||||
|
||||
@@ -567,14 +567,14 @@ template <class T>
|
||||
bool
|
||||
SharedWeakUnion<T>::isStrong() const
|
||||
{
|
||||
return (tp_ & kTAG_MASK) == 0u;
|
||||
return (tp_ & kTagMask) == 0u;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
bool
|
||||
SharedWeakUnion<T>::isWeak() const
|
||||
{
|
||||
return (tp_ & kTAG_MASK) != 0u;
|
||||
return (tp_ & kTagMask) != 0u;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
@@ -641,7 +641,7 @@ template <class T>
|
||||
T*
|
||||
SharedWeakUnion<T>::unsafeGetRawPtr() const
|
||||
{
|
||||
return reinterpret_cast<T*>(tp_ & kPTR_MASK);
|
||||
return reinterpret_cast<T*>(tp_ & kPtrMask);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
@@ -650,7 +650,7 @@ SharedWeakUnion<T>::unsafeSetRawPtr(T* p, RefStrength rs)
|
||||
{
|
||||
tp_ = reinterpret_cast<std::uintptr_t>(p);
|
||||
if (tp_ && rs == RefStrength::Weak)
|
||||
tp_ |= kTAG_MASK;
|
||||
tp_ |= kTagMask;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
|
||||
@@ -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 kSTRONG_COUNT_NUM_BITS = sizeof(CountType) * 8;
|
||||
static constexpr size_t kWEAK_COUNT_NUM_BITS = kSTRONG_COUNT_NUM_BITS - 2;
|
||||
static constexpr size_t kStrongCountNumBits = sizeof(CountType) * 8;
|
||||
static constexpr size_t kWeakCountNumBits = kStrongCountNumBits - 2;
|
||||
using FieldType = std::uint32_t;
|
||||
static constexpr size_t kFIELD_TYPE_BITS = sizeof(FieldType) * 8;
|
||||
static constexpr FieldType kONE = 1;
|
||||
static constexpr size_t kFieldTypeBits = 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<FieldType> refCounts_{kSTRONG_DELTA};
|
||||
mutable std::atomic<FieldType> refCounts_{kStrongDelta};
|
||||
|
||||
/** 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 kSTRONG_DELTA = 1;
|
||||
static constexpr FieldType kStrongDelta = 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 kWEAK_DELTA = (kONE << kSTRONG_COUNT_NUM_BITS);
|
||||
static constexpr FieldType kWeakDelta = (kOne << kStrongCountNumBits);
|
||||
|
||||
/** Flag that is set when the partialDestroy function has started running
|
||||
(or is about to start running).
|
||||
@@ -159,34 +159,33 @@ private:
|
||||
See description of the `refCounts` field for a fuller description of
|
||||
this field.
|
||||
*/
|
||||
static constexpr FieldType kPARTIAL_DESTROY_STARTED_MASK = (kONE << (kFIELD_TYPE_BITS - 1));
|
||||
static constexpr FieldType kPartialDestroyStartedMask = (kOne << (kFieldTypeBits - 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 kPARTIAL_DESTROY_FINISHED_MASK = (kONE << (kFIELD_TYPE_BITS - 2));
|
||||
static constexpr FieldType kPartialDestroyFinishedMask = (kOne << (kFieldTypeBits - 2));
|
||||
|
||||
/** Mask that will zero out all the `count` bits and leave the tag bits
|
||||
unchanged.
|
||||
*/
|
||||
static constexpr FieldType kTAG_MASK =
|
||||
kPARTIAL_DESTROY_STARTED_MASK | kPARTIAL_DESTROY_FINISHED_MASK;
|
||||
static constexpr FieldType kTagMask = kPartialDestroyStartedMask | kPartialDestroyFinishedMask;
|
||||
|
||||
/** Mask that will zero out the `tag` bits and leave the count bits
|
||||
unchanged.
|
||||
*/
|
||||
static constexpr FieldType kVALUE_MASK = ~kTAG_MASK;
|
||||
static constexpr FieldType kValueMask = ~kTagMask;
|
||||
|
||||
/** Mask that will zero out everything except the strong count.
|
||||
*/
|
||||
static constexpr FieldType kSTRONG_MASK = ((kONE << kSTRONG_COUNT_NUM_BITS) - 1) & kVALUE_MASK;
|
||||
static constexpr FieldType kStrongMask = ((kOne << kStrongCountNumBits) - 1) & kValueMask;
|
||||
|
||||
/** Mask that will zero out everything except the weak count.
|
||||
*/
|
||||
static constexpr FieldType kWEAK_MASK =
|
||||
(((kONE << kWEAK_COUNT_NUM_BITS) - 1) << kSTRONG_COUNT_NUM_BITS) & kVALUE_MASK;
|
||||
static constexpr FieldType kWeakMask =
|
||||
(((kOne << kWeakCountNumBits) - 1) << kStrongCountNumBits) & kValueMask;
|
||||
|
||||
/** Unpack the count and tag fields from the packed atomic integer form. */
|
||||
struct RefCountPair
|
||||
@@ -211,29 +210,29 @@ private:
|
||||
[[nodiscard]] FieldType
|
||||
combinedValue() const noexcept;
|
||||
|
||||
static constexpr CountType kMAX_STRONG_VALUE =
|
||||
static_cast<CountType>((kONE << kSTRONG_COUNT_NUM_BITS) - 1);
|
||||
static constexpr CountType kMAX_WEAK_VALUE =
|
||||
static_cast<CountType>((kONE << kWEAK_COUNT_NUM_BITS) - 1);
|
||||
static constexpr CountType kMaxStrongValue =
|
||||
static_cast<CountType>((kOne << kStrongCountNumBits) - 1);
|
||||
static constexpr CountType kMaxWeakValue =
|
||||
static_cast<CountType>((kOne << kWeakCountNumBits) - 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 kCHECK_STRONG_MAX_VALUE = kMAX_STRONG_VALUE - 32;
|
||||
static constexpr CountType kCHECK_WEAK_MAX_VALUE = kMAX_WEAK_VALUE - 32;
|
||||
static constexpr CountType kCheckStrongMaxValue = kMaxStrongValue - 32;
|
||||
static constexpr CountType kCheckWeakMaxValue = kMaxWeakValue - 32;
|
||||
};
|
||||
};
|
||||
|
||||
inline void
|
||||
IntrusiveRefCounts::addStrongRef() const noexcept
|
||||
{
|
||||
refCounts_.fetch_add(kSTRONG_DELTA, std::memory_order_acq_rel);
|
||||
refCounts_.fetch_add(kStrongDelta, std::memory_order_acq_rel);
|
||||
}
|
||||
|
||||
inline void
|
||||
IntrusiveRefCounts::addWeakRef() const noexcept
|
||||
{
|
||||
refCounts_.fetch_add(kWEAK_DELTA, std::memory_order_acq_rel);
|
||||
refCounts_.fetch_add(kWeakDelta, std::memory_order_acq_rel);
|
||||
}
|
||||
|
||||
inline ReleaseStrongRefAction
|
||||
@@ -252,10 +251,10 @@ IntrusiveRefCounts::releaseStrongRef() const
|
||||
{
|
||||
RefCountPair const prevVal{prevIntVal};
|
||||
XRPL_ASSERT(
|
||||
(prevVal.strong >= kSTRONG_DELTA),
|
||||
(prevVal.strong >= kStrongDelta),
|
||||
"xrpl::IntrusiveRefCounts::releaseStrongRef : previous ref "
|
||||
"higher than new");
|
||||
auto nextIntVal = prevIntVal - kSTRONG_DELTA;
|
||||
auto nextIntVal = prevIntVal - kStrongDelta;
|
||||
ReleaseStrongRefAction action = NoOp;
|
||||
if (prevVal.strong == 1)
|
||||
{
|
||||
@@ -265,7 +264,7 @@ IntrusiveRefCounts::releaseStrongRef() const
|
||||
}
|
||||
else
|
||||
{
|
||||
nextIntVal |= kPARTIAL_DESTROY_STARTED_MASK;
|
||||
nextIntVal |= kPartialDestroyStartedMask;
|
||||
action = PartialDestroy;
|
||||
}
|
||||
}
|
||||
@@ -276,7 +275,7 @@ IntrusiveRefCounts::releaseStrongRef() const
|
||||
// count to zero can start a partial destroy, and that can't happen
|
||||
// twice.
|
||||
XRPL_ASSERT(
|
||||
(action == NoOp) || !(prevIntVal & kPARTIAL_DESTROY_STARTED_MASK),
|
||||
(action == NoOp) || !(prevIntVal & kPartialDestroyStartedMask),
|
||||
"xrpl::IntrusiveRefCounts::releaseStrongRef : not in partial "
|
||||
"destroy");
|
||||
return action;
|
||||
@@ -289,8 +288,8 @@ IntrusiveRefCounts::addWeakReleaseStrongRef() const
|
||||
{
|
||||
using enum ReleaseStrongRefAction;
|
||||
|
||||
static_assert(kWEAK_DELTA > kSTRONG_DELTA);
|
||||
auto constexpr kDELTA = kWEAK_DELTA - kSTRONG_DELTA;
|
||||
static_assert(kWeakDelta > kStrongDelta);
|
||||
static constexpr auto kDelta = kWeakDelta - kStrongDelta;
|
||||
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
|
||||
@@ -312,7 +311,7 @@ IntrusiveRefCounts::addWeakReleaseStrongRef() const
|
||||
"xrpl::IntrusiveRefCounts::addWeakReleaseStrongRef : not in "
|
||||
"partial destroy");
|
||||
|
||||
auto nextIntVal = prevIntVal + kDELTA;
|
||||
auto nextIntVal = prevIntVal + kDelta;
|
||||
ReleaseStrongRefAction action = NoOp;
|
||||
if (prevVal.strong == 1)
|
||||
{
|
||||
@@ -322,14 +321,14 @@ IntrusiveRefCounts::addWeakReleaseStrongRef() const
|
||||
}
|
||||
else
|
||||
{
|
||||
nextIntVal |= kPARTIAL_DESTROY_STARTED_MASK;
|
||||
nextIntVal |= kPartialDestroyStartedMask;
|
||||
action = PartialDestroy;
|
||||
}
|
||||
}
|
||||
if (refCounts_.compare_exchange_weak(prevIntVal, nextIntVal, std::memory_order_acq_rel))
|
||||
{
|
||||
XRPL_ASSERT(
|
||||
(!(prevIntVal & kPARTIAL_DESTROY_STARTED_MASK)),
|
||||
(!(prevIntVal & kPartialDestroyStartedMask)),
|
||||
"xrpl::IntrusiveRefCounts::addWeakReleaseStrongRef : not "
|
||||
"started partial destroy");
|
||||
return action;
|
||||
@@ -340,7 +339,7 @@ IntrusiveRefCounts::addWeakReleaseStrongRef() const
|
||||
inline ReleaseWeakRefAction
|
||||
IntrusiveRefCounts::releaseWeakRef() const
|
||||
{
|
||||
auto prevIntVal = refCounts_.fetch_sub(kWEAK_DELTA, std::memory_order_acq_rel);
|
||||
auto prevIntVal = refCounts_.fetch_sub(kWeakDelta, std::memory_order_acq_rel);
|
||||
RefCountPair prev = prevIntVal;
|
||||
if (prev.weak == 1 && prev.strong == 0)
|
||||
{
|
||||
@@ -357,7 +356,7 @@ IntrusiveRefCounts::releaseWeakRef() const
|
||||
{
|
||||
// partial destroy MUST finish before running a full destroy (when
|
||||
// using weak pointers)
|
||||
refCounts_.wait(prevIntVal - kWEAK_DELTA, std::memory_order_acquire);
|
||||
refCounts_.wait(prevIntVal - kWeakDelta, std::memory_order_acquire);
|
||||
}
|
||||
return ReleaseWeakRefAction::Destroy;
|
||||
}
|
||||
@@ -376,7 +375,7 @@ IntrusiveRefCounts::checkoutStrongRefFromWeak() const noexcept
|
||||
if (prev.strong == 0u)
|
||||
return false;
|
||||
|
||||
desiredValue = curValue + kSTRONG_DELTA;
|
||||
desiredValue = curValue + kStrongDelta;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -400,23 +399,22 @@ inline IntrusiveRefCounts::~IntrusiveRefCounts() noexcept
|
||||
#ifndef NDEBUG
|
||||
auto v = refCounts_.load(std::memory_order_acquire);
|
||||
XRPL_ASSERT(
|
||||
(!(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");
|
||||
(!(v & kValueMask)), "xrpl::IntrusiveRefCounts::~IntrusiveRefCounts : count must be zero");
|
||||
auto t = v & kTagMask;
|
||||
XRPL_ASSERT((!t || t == kTagMask), "xrpl::IntrusiveRefCounts::~IntrusiveRefCounts : valid tag");
|
||||
#endif
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
inline IntrusiveRefCounts::RefCountPair::RefCountPair(IntrusiveRefCounts::FieldType v) noexcept
|
||||
: strong{static_cast<CountType>(v & kSTRONG_MASK)}
|
||||
, weak{static_cast<CountType>((v & kWEAK_MASK) >> kSTRONG_COUNT_NUM_BITS)}
|
||||
, partialDestroyStartedBit{v & kPARTIAL_DESTROY_STARTED_MASK}
|
||||
, partialDestroyFinishedBit{v & kPARTIAL_DESTROY_FINISHED_MASK}
|
||||
: strong{static_cast<CountType>(v & kStrongMask)}
|
||||
, weak{static_cast<CountType>((v & kWeakMask) >> kStrongCountNumBits)}
|
||||
, partialDestroyStartedBit{v & kPartialDestroyStartedMask}
|
||||
, partialDestroyFinishedBit{v & kPartialDestroyFinishedMask}
|
||||
{
|
||||
XRPL_ASSERT(
|
||||
(strong < kCHECK_STRONG_MAX_VALUE && weak < kCHECK_WEAK_MAX_VALUE),
|
||||
(strong < kCheckStrongMaxValue && weak < kCheckWeakMaxValue),
|
||||
"xrpl::IntrusiveRefCounts::RefCountPair(FieldType) : inputs inside "
|
||||
"range");
|
||||
}
|
||||
@@ -427,7 +425,7 @@ inline IntrusiveRefCounts::RefCountPair::RefCountPair(
|
||||
: strong{s}, weak{w}
|
||||
{
|
||||
XRPL_ASSERT(
|
||||
(strong < kCHECK_STRONG_MAX_VALUE && weak < kCHECK_WEAK_MAX_VALUE),
|
||||
(strong < kCheckStrongMaxValue && weak < kCheckWeakMaxValue),
|
||||
"xrpl::IntrusiveRefCounts::RefCountPair(CountType, CountType) : "
|
||||
"inputs inside range");
|
||||
}
|
||||
@@ -436,11 +434,11 @@ inline IntrusiveRefCounts::FieldType
|
||||
IntrusiveRefCounts::RefCountPair::combinedValue() const noexcept
|
||||
{
|
||||
XRPL_ASSERT(
|
||||
(strong < kCHECK_STRONG_MAX_VALUE && weak < kCHECK_WEAK_MAX_VALUE),
|
||||
(strong < kCheckStrongMaxValue && weak < kCheckWeakMaxValue),
|
||||
"xrpl::IntrusiveRefCounts::RefCountPair::combinedValue : inputs "
|
||||
"inside range");
|
||||
return (static_cast<IntrusiveRefCounts::FieldType>(weak)
|
||||
<< IntrusiveRefCounts::kSTRONG_COUNT_NUM_BITS) |
|
||||
<< IntrusiveRefCounts::kStrongCountNumBits) |
|
||||
static_cast<IntrusiveRefCounts::FieldType>(strong) | partialDestroyStartedBit |
|
||||
partialDestroyFinishedBit;
|
||||
}
|
||||
@@ -451,7 +449,7 @@ partialDestructorFinished(T** o)
|
||||
{
|
||||
T& self = **o;
|
||||
IntrusiveRefCounts::RefCountPair const p =
|
||||
self.refCounts_.fetch_or(IntrusiveRefCounts::kPARTIAL_DESTROY_FINISHED_MASK);
|
||||
self.refCounts_.fetch_or(IntrusiveRefCounts::kPartialDestroyFinishedMask);
|
||||
XRPL_ASSERT(
|
||||
(!p.partialDestroyFinishedBit && p.partialDestroyStartedBit && !p.strong),
|
||||
"xrpl::partialDestructorFinished : not a weak ref");
|
||||
|
||||
@@ -55,8 +55,8 @@ template <class = void>
|
||||
boost::thread_specific_ptr<detail::LocalValues>&
|
||||
getLocalValues()
|
||||
{
|
||||
static boost::thread_specific_ptr<detail::LocalValues> kTSP(&detail::LocalValues::cleanup);
|
||||
return kTSP;
|
||||
static boost::thread_specific_ptr<detail::LocalValues> kTsp(&detail::LocalValues::cleanup);
|
||||
return kTsp;
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
|
||||
@@ -191,7 +191,7 @@ public:
|
||||
private:
|
||||
// Maximum line length for log messages.
|
||||
// If the message exceeds this length it will be truncated with ellipses.
|
||||
static constexpr auto kMAXIMUM_MESSAGE_CHARACTERS = 12 * 1024;
|
||||
static constexpr auto kMaximumMessageCharacters = 12 * 1024;
|
||||
|
||||
static void
|
||||
format(
|
||||
|
||||
@@ -214,12 +214,12 @@ class Number
|
||||
|
||||
public:
|
||||
// The range for the exponent when normalized
|
||||
constexpr static int kMIN_EXPONENT = -32768;
|
||||
constexpr static int kMAX_EXPONENT = 32768;
|
||||
static constexpr int kMinExponent = -32768;
|
||||
static constexpr int kMaxExponent = 32768;
|
||||
|
||||
constexpr static internalrep kMAX_REP = std::numeric_limits<rep>::max();
|
||||
static_assert(kMAX_REP == 9'223'372'036'854'775'807);
|
||||
static_assert(-kMAX_REP == std::numeric_limits<rep>::min() + 1);
|
||||
static constexpr internalrep kMaxRep = std::numeric_limits<rep>::max();
|
||||
static_assert(kMaxRep == 9'223'372'036'854'775'807);
|
||||
static_assert(-kMaxRep == std::numeric_limits<rep>::min() + 1);
|
||||
|
||||
// May need to make unchecked private
|
||||
struct Unchecked
|
||||
@@ -409,26 +409,26 @@ public:
|
||||
static internalrep
|
||||
minMantissa()
|
||||
{
|
||||
return kRANGE.get().min;
|
||||
return kRange.get().min;
|
||||
}
|
||||
|
||||
static internalrep
|
||||
maxMantissa()
|
||||
{
|
||||
return kRANGE.get().max;
|
||||
return kRange.get().max;
|
||||
}
|
||||
|
||||
static int
|
||||
mantissaLog()
|
||||
{
|
||||
return kRANGE.get().log;
|
||||
return kRange.get().log;
|
||||
}
|
||||
|
||||
/// oneSmall is needed because the ranges are private
|
||||
constexpr static Number
|
||||
static constexpr Number
|
||||
oneSmall();
|
||||
/// oneLarge is needed because the ranges are private
|
||||
constexpr static Number
|
||||
static constexpr Number
|
||||
oneLarge();
|
||||
|
||||
// And one is needed because it needs to choose between oneSmall and
|
||||
@@ -445,25 +445,25 @@ private:
|
||||
static thread_local RoundingMode mode;
|
||||
// The available ranges for mantissa
|
||||
|
||||
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);
|
||||
static constexpr MantissaRange kSmallRange{MantissaRange::MantissaScale::Small};
|
||||
static_assert(isPowerOfTen(kSmallRange.min));
|
||||
static_assert(kSmallRange.min == 1'000'000'000'000'000LL);
|
||||
static_assert(kSmallRange.max == 9'999'999'999'999'999LL);
|
||||
static_assert(kSmallRange.log == 15);
|
||||
static_assert(kSmallRange.min < kMaxRep);
|
||||
static_assert(kSmallRange.max < kMaxRep);
|
||||
static constexpr MantissaRange kLargeRange{MantissaRange::MantissaScale::Large};
|
||||
static_assert(isPowerOfTen(kLargeRange.min));
|
||||
static_assert(kLargeRange.min == 1'000'000'000'000'000'000ULL);
|
||||
static_assert(kLargeRange.max == internalrep(9'999'999'999'999'999'999ULL));
|
||||
static_assert(kLargeRange.log == 18);
|
||||
static_assert(kLargeRange.min < kMaxRep);
|
||||
static_assert(kLargeRange.max > kMaxRep);
|
||||
|
||||
// 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<MantissaRange const> kRANGE;
|
||||
static thread_local std::reference_wrapper<MantissaRange const> kRange;
|
||||
|
||||
void
|
||||
normalize();
|
||||
@@ -471,7 +471,7 @@ private:
|
||||
/** Normalize Number components to an arbitrary range.
|
||||
*
|
||||
* min/maxMantissa are parameters because this function is used by both
|
||||
* normalize(), which reads from kRANGE, and by normalizeToRange,
|
||||
* normalize(), which reads from kRange, and by normalizeToRange,
|
||||
* which is public and can accept an arbitrary range from the caller.
|
||||
*/
|
||||
template <class T>
|
||||
@@ -521,7 +521,7 @@ constexpr Number::Number(internalrep mantissa, int exponent, Unchecked) noexcept
|
||||
{
|
||||
}
|
||||
|
||||
constexpr static Number kNUM_ZERO{};
|
||||
static constexpr Number kNumZero{};
|
||||
|
||||
inline Number::Number(bool negative, internalrep mantissa, int exponent, Normalized)
|
||||
: Number(negative, mantissa, exponent, Unchecked{})
|
||||
@@ -552,10 +552,10 @@ constexpr Number::rep
|
||||
Number::mantissa() const noexcept
|
||||
{
|
||||
auto m = mantissa_;
|
||||
if (m > kMAX_REP)
|
||||
if (m > kMaxRep)
|
||||
{
|
||||
XRPL_ASSERT_PARTS(
|
||||
!isnormal() || (m % 10 == 0 && m / 10 <= kMAX_REP),
|
||||
!isnormal() || (m % 10 == 0 && m / 10 <= kMaxRep),
|
||||
"xrpl::Number::mantissa",
|
||||
"large normalized mantissa has no remainder");
|
||||
m /= 10;
|
||||
@@ -573,10 +573,10 @@ constexpr int
|
||||
Number::exponent() const noexcept
|
||||
{
|
||||
auto e = exponent_;
|
||||
if (mantissa_ > kMAX_REP)
|
||||
if (mantissa_ > kMaxRep)
|
||||
{
|
||||
XRPL_ASSERT_PARTS(
|
||||
!isnormal() || (mantissa_ % 10 == 0 && mantissa_ / 10 <= kMAX_REP),
|
||||
!isnormal() || (mantissa_ % 10 == 0 && mantissa_ / 10 <= kMaxRep),
|
||||
"xrpl::Number::exponent",
|
||||
"large normalized mantissa has no remainder");
|
||||
++e;
|
||||
@@ -671,29 +671,29 @@ operator/(Number const& x, Number const& y)
|
||||
inline Number
|
||||
Number::min() noexcept
|
||||
{
|
||||
return Number{false, kRANGE.get().min, kMIN_EXPONENT, Unchecked{}};
|
||||
return Number{false, kRange.get().min, kMinExponent, Unchecked{}};
|
||||
}
|
||||
|
||||
inline Number
|
||||
Number::max() noexcept
|
||||
{
|
||||
return Number{false, std::min(kRANGE.get().max, kMAX_REP), kMAX_EXPONENT, Unchecked{}};
|
||||
return Number{false, std::min(kRange.get().max, kMaxRep), kMaxExponent, Unchecked{}};
|
||||
}
|
||||
|
||||
inline Number
|
||||
Number::lowest() noexcept
|
||||
{
|
||||
return Number{true, std::min(kRANGE.get().max, kMAX_REP), kMAX_EXPONENT, Unchecked{}};
|
||||
return Number{true, std::min(kRange.get().max, kMaxRep), kMaxExponent, Unchecked{}};
|
||||
}
|
||||
|
||||
inline bool
|
||||
Number::isnormal() const noexcept
|
||||
{
|
||||
MantissaRange const& range = kRANGE;
|
||||
MantissaRange const& range = kRange;
|
||||
auto const absM = mantissa_;
|
||||
return *this == Number{} ||
|
||||
(range.min <= absM && absM <= range.max && (absM <= kMAX_REP || absM % 10 == 0) &&
|
||||
kMIN_EXPONENT <= exponent_ && exponent_ <= kMAX_EXPONENT);
|
||||
(range.min <= absM && absM <= range.max && (absM <= kMaxRep || absM % 10 == 0) &&
|
||||
kMinExponent <= exponent_ && exponent_ <= kMaxExponent);
|
||||
}
|
||||
|
||||
template <Integral64 T>
|
||||
|
||||
@@ -57,10 +57,10 @@ template <class T>
|
||||
std::shared_ptr<T> const&
|
||||
SharedWeakCachePointer<T>::getStrong() const
|
||||
{
|
||||
static std::shared_ptr<T> const kEMPTY;
|
||||
static std::shared_ptr<T> const kEmpty;
|
||||
if (auto p = std::get_if<std::shared_ptr<T>>(&combo_))
|
||||
return *p;
|
||||
return kEMPTY;
|
||||
return kEmpty;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
|
||||
@@ -34,7 +34,7 @@ template <typename T>
|
||||
concept SomeChar = std::same_as<std::remove_cvref_t<T>, int8_t> ||
|
||||
std::same_as<std::remove_cvref_t<T>, char> || std::same_as<std::remove_cvref_t<T>, uint8_t>;
|
||||
|
||||
inline constexpr std::array<std::optional<int>, 256> const kDIGIT_LOOKUP_TABLE = []() {
|
||||
inline constexpr std::array<std::optional<int>, 256> const kDigitLookupTable = []() {
|
||||
std::array<std::optional<int>, 256> t{};
|
||||
|
||||
for (int i = 0; i < 10; ++i)
|
||||
@@ -52,7 +52,7 @@ inline constexpr std::array<std::optional<int>, 256> const kDIGIT_LOOKUP_TABLE =
|
||||
inline std::optional<int>
|
||||
hexCharToInt(SomeChar auto hexChar)
|
||||
{
|
||||
return kDIGIT_LOOKUP_TABLE[static_cast<uint8_t>(hexChar)];
|
||||
return kDigitLookupTable[static_cast<uint8_t>(hexChar)];
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
|
||||
@@ -30,8 +30,8 @@ public:
|
||||
now(); // seconds since xrpld program start
|
||||
|
||||
private:
|
||||
static std::atomic<rep> kNOW;
|
||||
static std::atomic<bool> kSTOP;
|
||||
static std::atomic<rep> kNow;
|
||||
static std::atomic<bool> kStop;
|
||||
|
||||
struct UpdateThread : private std::thread
|
||||
{
|
||||
|
||||
@@ -73,12 +73,12 @@ class BaseUInt
|
||||
|
||||
static_assert(Bits >= 64, "The length of a base_uint in bits must be at least 64.");
|
||||
|
||||
static constexpr std::size_t kWIDTH = 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<std::uint32_t, kWIDTH> data_;
|
||||
std::array<std::uint32_t, kWidth> data_;
|
||||
|
||||
public:
|
||||
//--------------------------------------------------------------------------
|
||||
@@ -86,8 +86,8 @@ public:
|
||||
// STL Container Interface
|
||||
//
|
||||
|
||||
static std::size_t constexpr kBYTES = Bits / 8;
|
||||
static_assert(sizeof(data_) == kBYTES, "");
|
||||
static constexpr std::size_t kBytes = Bits / 8;
|
||||
static_assert(sizeof(data_) == kBytes, "");
|
||||
|
||||
using size_type = std::size_t;
|
||||
using difference_type = std::ptrdiff_t;
|
||||
@@ -121,7 +121,7 @@ public:
|
||||
iterator
|
||||
end()
|
||||
{
|
||||
return data() + kBYTES;
|
||||
return data() + kBytes;
|
||||
}
|
||||
[[nodiscard]] const_iterator
|
||||
begin() const
|
||||
@@ -131,7 +131,7 @@ public:
|
||||
[[nodiscard]] const_iterator
|
||||
end() const
|
||||
{
|
||||
return data() + kBYTES;
|
||||
return data() + kBytes;
|
||||
}
|
||||
[[nodiscard]] const_iterator
|
||||
cbegin() const
|
||||
@@ -141,7 +141,7 @@ public:
|
||||
[[nodiscard]] const_iterator
|
||||
cend() const
|
||||
{
|
||||
return data() + kBYTES;
|
||||
return data() + kBytes;
|
||||
}
|
||||
|
||||
/** Value hashing function.
|
||||
@@ -167,7 +167,7 @@ private:
|
||||
|
||||
explicit BaseUInt(void const* data, VoidHelper)
|
||||
{
|
||||
memcpy(data_.data(), data, kBYTES);
|
||||
memcpy(data_.data(), data, kBytes);
|
||||
}
|
||||
|
||||
// Helper function to initialize a base_uint from a std::string_view.
|
||||
@@ -336,7 +336,7 @@ public:
|
||||
[[nodiscard]] constexpr int
|
||||
signum() const
|
||||
{
|
||||
for (int i = 0; i < kWIDTH; i++)
|
||||
for (int i = 0; i < kWidth; i++)
|
||||
{
|
||||
if (data_[i] != 0)
|
||||
return 1;
|
||||
@@ -348,7 +348,7 @@ public:
|
||||
bool
|
||||
operator!() const
|
||||
{
|
||||
return *this == beast::kZERO;
|
||||
return *this == beast::kZero;
|
||||
}
|
||||
|
||||
constexpr BaseUInt
|
||||
@@ -356,7 +356,7 @@ public:
|
||||
{
|
||||
BaseUInt ret;
|
||||
|
||||
for (int i = 0; i < kWIDTH; i++)
|
||||
for (int i = 0; i < kWidth; i++)
|
||||
ret.data_[i] = ~data_[i];
|
||||
|
||||
return ret;
|
||||
@@ -365,7 +365,7 @@ public:
|
||||
BaseUInt&
|
||||
operator=(std::uint64_t uHost)
|
||||
{
|
||||
*this = beast::kZERO;
|
||||
*this = beast::kZero;
|
||||
// NOLINTBEGIN(cppcoreguidelines-pro-type-member-init)
|
||||
union
|
||||
{
|
||||
@@ -375,15 +375,15 @@ public:
|
||||
// NOLINTEND(cppcoreguidelines-pro-type-member-init)
|
||||
// Put in least significant bits.
|
||||
ul = boost::endian::native_to_big(uHost);
|
||||
data_[kWIDTH - 2] = u[0];
|
||||
data_[kWIDTH - 1] = u[1];
|
||||
data_[kWidth - 2] = u[0];
|
||||
data_[kWidth - 1] = u[1];
|
||||
return *this;
|
||||
}
|
||||
|
||||
BaseUInt&
|
||||
operator^=(BaseUInt const& b)
|
||||
{
|
||||
for (int i = 0; i < kWIDTH; i++)
|
||||
for (int i = 0; i < kWidth; i++)
|
||||
data_[i] ^= b.data_[i];
|
||||
|
||||
return *this;
|
||||
@@ -392,7 +392,7 @@ public:
|
||||
BaseUInt&
|
||||
operator&=(BaseUInt const& b)
|
||||
{
|
||||
for (int i = 0; i < kWIDTH; i++)
|
||||
for (int i = 0; i < kWidth; i++)
|
||||
data_[i] &= b.data_[i];
|
||||
|
||||
return *this;
|
||||
@@ -401,7 +401,7 @@ public:
|
||||
BaseUInt&
|
||||
operator|=(BaseUInt const& b)
|
||||
{
|
||||
for (int i = 0; i < kWIDTH; i++)
|
||||
for (int i = 0; i < kWidth; i++)
|
||||
data_[i] |= b.data_[i];
|
||||
|
||||
return *this;
|
||||
@@ -411,7 +411,7 @@ public:
|
||||
operator++()
|
||||
{
|
||||
// prefix operator
|
||||
for (int i = kWIDTH - 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)
|
||||
@@ -434,7 +434,7 @@ public:
|
||||
BaseUInt&
|
||||
operator--()
|
||||
{
|
||||
for (int i = kWIDTH - 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);
|
||||
@@ -475,7 +475,7 @@ public:
|
||||
{
|
||||
std::uint64_t carry = 0;
|
||||
|
||||
for (int i = kWIDTH - 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]);
|
||||
@@ -526,10 +526,10 @@ public:
|
||||
return parseHex(std::string_view{str});
|
||||
}
|
||||
|
||||
constexpr static std::size_t
|
||||
static constexpr std::size_t
|
||||
size()
|
||||
{
|
||||
return kBYTES;
|
||||
return kBytes;
|
||||
}
|
||||
|
||||
BaseUInt<Bits, Tag>&
|
||||
@@ -543,17 +543,17 @@ public:
|
||||
[[nodiscard]] bool
|
||||
isZero() const
|
||||
{
|
||||
return *this == beast::kZERO;
|
||||
return *this == beast::kZero;
|
||||
}
|
||||
[[nodiscard]] bool
|
||||
isNonZero() const
|
||||
{
|
||||
return *this != beast::kZERO;
|
||||
return *this != beast::kZero;
|
||||
}
|
||||
void
|
||||
zero()
|
||||
{
|
||||
*this = beast::kZERO;
|
||||
*this = beast::kZero;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -639,7 +639,7 @@ template <std::size_t Bits, class Tag>
|
||||
inline std::string
|
||||
toShortString(BaseUInt<Bits, Tag> const& a)
|
||||
{
|
||||
static_assert(BaseUInt<Bits, Tag>::kBYTES > 4, "For 4 bytes or less, use a native type");
|
||||
static_assert(BaseUInt<Bits, Tag>::kBytes > 4, "For 4 bytes or less, use a native type");
|
||||
return strHex(a.cbegin(), a.cbegin() + 4) + "...";
|
||||
}
|
||||
|
||||
|
||||
@@ -30,10 +30,10 @@ using weeks = std::chrono::duration<int, std::ratio_multiply<days::period, std::
|
||||
= seconds(946684800)
|
||||
*/
|
||||
|
||||
constexpr static std::chrono::seconds kEPOCH_OFFSET =
|
||||
static constexpr std::chrono::seconds kEpochOffset =
|
||||
date::sys_days{date::year{2000} / 1 / 1} - date::sys_days{date::year{1970} / 1 / 1};
|
||||
|
||||
static_assert(kEPOCH_OFFSET.count() == 946684800);
|
||||
static_assert(kEpochOffset.count() == 946684800);
|
||||
|
||||
class NetClock
|
||||
{
|
||||
@@ -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() + kEPOCH_OFFSET});
|
||||
return to_string(system_clock::time_point{tp.time_since_epoch() + kEpochOffset});
|
||||
}
|
||||
|
||||
template <class Duration>
|
||||
@@ -77,7 +77,7 @@ toStringIso(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<NetClock::duration::period, std::ratio<1>>);
|
||||
return toStringIso(date::sys_time<NetClock::duration>{tp.time_since_epoch() + kEPOCH_OFFSET});
|
||||
return toStringIso(date::sys_time<NetClock::duration>{tp.time_since_epoch() + kEpochOffset});
|
||||
}
|
||||
|
||||
/** A clock for measuring elapsed time.
|
||||
|
||||
@@ -31,9 +31,9 @@ makeSeedPair() noexcept
|
||||
// state_t(state_t const&) = delete;
|
||||
// state_t& operator=(state_t const&) = delete;
|
||||
};
|
||||
static StateT kSTATE;
|
||||
std::scoped_lock const lock(kSTATE.mutex);
|
||||
return {kSTATE.dist(kSTATE.gen), kSTATE.dist(kSTATE.gen)};
|
||||
static StateT kState;
|
||||
std::scoped_lock const lock(kState.mutex);
|
||||
return {kState.dist(kState.gen), kState.dist(kState.gen)};
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include <optional>
|
||||
|
||||
namespace xrpl {
|
||||
auto constexpr kMULDIV_MAX = std::numeric_limits<std::uint64_t>::max();
|
||||
constexpr auto kMuldivMax = std::numeric_limits<std::uint64_t>::max();
|
||||
|
||||
/** Return value*mul/div accurately.
|
||||
Computes the result of the multiplication and division in
|
||||
|
||||
@@ -47,7 +47,7 @@ inline beast::xor_shift_engine&
|
||||
defaultPrng()
|
||||
{
|
||||
// This is used to seed the thread-specific PRNGs on demand
|
||||
static beast::xor_shift_engine kSEEDER = [] {
|
||||
static beast::xor_shift_engine kSeeder = [] {
|
||||
std::random_device rng;
|
||||
std::uniform_int_distribution<std::uint64_t> distribution{1};
|
||||
return beast::xor_shift_engine(distribution(rng));
|
||||
@@ -57,17 +57,17 @@ defaultPrng()
|
||||
static std::mutex kM;
|
||||
|
||||
// The thread-specific PRNGs:
|
||||
thread_local beast::xor_shift_engine kENGINE = [] {
|
||||
thread_local beast::xor_shift_engine kEngine = [] {
|
||||
std::uint64_t seed = 0;
|
||||
{
|
||||
std::scoped_lock const lk(kM);
|
||||
std::uniform_int_distribution<std::uint64_t> distribution{1};
|
||||
seed = distribution(kSEEDER);
|
||||
seed = distribution(kSeeder);
|
||||
}
|
||||
return beast::xor_shift_engine{seed};
|
||||
}();
|
||||
|
||||
return kENGINE;
|
||||
return kEngine;
|
||||
}
|
||||
|
||||
/** Return a uniformly distributed random integer.
|
||||
|
||||
@@ -22,9 +22,9 @@ safeCast(Src s) noexcept
|
||||
{
|
||||
static_assert(
|
||||
std::is_signed_v<Dest> || std::is_unsigned_v<Src>, "Cannot cast signed to unsigned");
|
||||
constexpr unsigned kNOT_SAME = std::is_signed_v<Dest> != std::is_signed_v<Src>;
|
||||
constexpr unsigned kNotSame = std::is_signed_v<Dest> != std::is_signed_v<Src>;
|
||||
static_assert(
|
||||
sizeof(Dest) >= sizeof(Src) + kNOT_SAME,
|
||||
sizeof(Dest) >= sizeof(Src) + kNotSame,
|
||||
"Destination is too small to hold all values of source");
|
||||
return static_cast<Dest>(s);
|
||||
}
|
||||
|
||||
@@ -83,8 +83,8 @@ template <class Facade, class Clock = Facade>
|
||||
AbstractClock<Facade>&
|
||||
getAbstractClock()
|
||||
{
|
||||
static detail::AbstractClockWrapper<Facade, Clock> kCLOCK;
|
||||
return kCLOCK;
|
||||
static detail::AbstractClockWrapper<Facade, Clock> kClock;
|
||||
return kClock;
|
||||
}
|
||||
|
||||
} // namespace beast
|
||||
|
||||
@@ -21,7 +21,7 @@ setCurrentThreadName(std::string_view newThreadName);
|
||||
|
||||
// On Linux, thread names are limited to 16 bytes including the null terminator.
|
||||
// Maximum number of characters is therefore 15.
|
||||
constexpr std::size_t kMAX_THREAD_NAME_LENGTH = 15;
|
||||
constexpr std::size_t kMaxThreadNameLength = 15;
|
||||
|
||||
/** Sets the name of the caller thread with compile-time size checking.
|
||||
@tparam N The size of the string literal including null terminator
|
||||
@@ -34,7 +34,7 @@ template <std::size_t N>
|
||||
void
|
||||
setCurrentThreadName(char const (&newThreadName)[N])
|
||||
{
|
||||
static_assert(N <= kMAX_THREAD_NAME_LENGTH + 1, "Thread name cannot exceed 15 characters");
|
||||
static_assert(N <= kMaxThreadNameLength + 1, "Thread name cannot exceed 15 characters");
|
||||
|
||||
setCurrentThreadName(std::string_view(newThreadName, N - 1));
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ inline void
|
||||
maybeReverseBytes(T& t, Hasher&)
|
||||
{
|
||||
maybeReverseBytes(
|
||||
t, std::integral_constant<bool, Hasher::kENDIAN != boost::endian::order::native>{});
|
||||
t, std::integral_constant<bool, Hasher::kEndian != boost::endian::order::native>{});
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
@@ -154,7 +154,7 @@ struct IsContiguouslyHashable
|
||||
: public std::integral_constant<
|
||||
bool,
|
||||
IsUniquelyRepresented<T>::value &&
|
||||
(sizeof(T) == 1 || HashAlgorithm::kENDIAN == boost::endian::order::native)>
|
||||
(sizeof(T) == 1 || HashAlgorithm::kEndian == boost::endian::order::native)>
|
||||
{
|
||||
explicit IsContiguouslyHashable() = default;
|
||||
};
|
||||
|
||||
@@ -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 kINTERNAL_BUFFER_SIZE = 64;
|
||||
static constexpr std::size_t kInternalBufferSize = 64;
|
||||
|
||||
alignas(64) std::array<std::uint8_t, kINTERNAL_BUFFER_SIZE> buffer_{};
|
||||
alignas(64) std::array<std::uint8_t, kInternalBufferSize> buffer_{};
|
||||
std::span<std::uint8_t> readBuffer_;
|
||||
std::span<std::uint8_t> writeBuffer_;
|
||||
|
||||
@@ -102,7 +102,7 @@ private:
|
||||
}
|
||||
|
||||
public:
|
||||
static constexpr auto const kENDIAN = boost::endian::order::native;
|
||||
static constexpr auto kEndian = boost::endian::order::native;
|
||||
|
||||
Xxhasher(Xxhasher const&) = delete;
|
||||
Xxhasher&
|
||||
|
||||
@@ -62,7 +62,7 @@ private:
|
||||
{
|
||||
using run_time = std::pair<std::string, typename clock_type::duration>;
|
||||
|
||||
static constexpr auto kMAX_TOP = 10;
|
||||
static constexpr auto kMaxTop = 10;
|
||||
|
||||
std::size_t suites = 0;
|
||||
std::size_t cases = 0;
|
||||
@@ -146,11 +146,11 @@ Reporter<Unused>::Results::add(SuiteResults const& r)
|
||||
});
|
||||
if (iter != top.end())
|
||||
{
|
||||
if (top.size() == kMAX_TOP)
|
||||
if (top.size() == kMaxTop)
|
||||
top.resize(top.size() - 1);
|
||||
top.emplace(iter, r.name, elapsed);
|
||||
}
|
||||
else if (top.size() < kMAX_TOP)
|
||||
else if (top.size() < kMaxTop)
|
||||
{
|
||||
top.emplace_back(r.name, elapsed);
|
||||
}
|
||||
|
||||
@@ -299,8 +299,8 @@ private:
|
||||
static Suite**
|
||||
pThisSuite()
|
||||
{
|
||||
static Suite* kP_TS = nullptr; // NOLINT TODO
|
||||
return &kP_TS;
|
||||
static Suite* kPTs = nullptr; // NOLINT TODO
|
||||
return &kPTs;
|
||||
}
|
||||
|
||||
/** Runs the suite. */
|
||||
|
||||
@@ -27,7 +27,7 @@ struct Zero
|
||||
};
|
||||
|
||||
namespace {
|
||||
constexpr Zero kZERO{};
|
||||
constexpr Zero kZero{};
|
||||
} // namespace
|
||||
|
||||
/** Default implementation of signum calls the method on the class. */
|
||||
@@ -102,42 +102,42 @@ template <typename T>
|
||||
bool
|
||||
operator==(Zero, T const& t)
|
||||
{
|
||||
return t == kZERO;
|
||||
return t == kZero;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool
|
||||
operator!=(Zero, T const& t)
|
||||
{
|
||||
return t != kZERO;
|
||||
return t != kZero;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool
|
||||
operator<(Zero, T const& t)
|
||||
{
|
||||
return t > kZERO;
|
||||
return t > kZero;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool
|
||||
operator>(Zero, T const& t)
|
||||
{
|
||||
return t < kZERO;
|
||||
return t < kZero;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool
|
||||
operator>=(Zero, T const& t)
|
||||
{
|
||||
return t <= kZERO;
|
||||
return t <= kZero;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool
|
||||
operator<=(Zero, T const& t)
|
||||
{
|
||||
return t >= kZERO;
|
||||
return t >= kZero;
|
||||
}
|
||||
|
||||
} // namespace beast
|
||||
|
||||
@@ -14,23 +14,23 @@ void
|
||||
rngfill(void* const buffer, std::size_t const bytes, Generator& g)
|
||||
{
|
||||
using result_type = typename Generator::result_type;
|
||||
constexpr std::size_t kRESULT_SIZE = sizeof(result_type);
|
||||
constexpr std::size_t kResultSize = sizeof(result_type);
|
||||
|
||||
std::uint8_t* const bufferStart = static_cast<std::uint8_t*>(buffer);
|
||||
std::size_t const completeIterations = bytes / kRESULT_SIZE;
|
||||
std::size_t const bytesRemaining = bytes % kRESULT_SIZE;
|
||||
std::size_t const completeIterations = bytes / kResultSize;
|
||||
std::size_t const bytesRemaining = bytes % kResultSize;
|
||||
|
||||
for (std::size_t count = 0; count < completeIterations; ++count)
|
||||
{
|
||||
result_type const v = g();
|
||||
std::size_t const offset = count * kRESULT_SIZE;
|
||||
std::memcpy(bufferStart + offset, &v, kRESULT_SIZE);
|
||||
std::size_t const offset = count * kResultSize;
|
||||
std::memcpy(bufferStart + offset, &v, kResultSize);
|
||||
}
|
||||
|
||||
if (bytesRemaining > 0)
|
||||
{
|
||||
result_type const v = g();
|
||||
std::size_t const offset = completeIterations * kRESULT_SIZE;
|
||||
std::size_t const offset = completeIterations * kResultSize;
|
||||
std::memcpy(bufferStart + offset, &v, bytesRemaining);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,12 +26,14 @@ public:
|
||||
result_type
|
||||
operator()();
|
||||
|
||||
static result_type constexpr min()
|
||||
static constexpr result_type
|
||||
min()
|
||||
{
|
||||
return std::numeric_limits<result_type>::min();
|
||||
}
|
||||
|
||||
static result_type constexpr max()
|
||||
static constexpr result_type
|
||||
max()
|
||||
{
|
||||
return std::numeric_limits<result_type>::max();
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ public:
|
||||
that were previously considered valid to no longer
|
||||
be allowed.
|
||||
*/
|
||||
static constexpr std::size_t kMAX_SERIALIZED_CONDITION = 128;
|
||||
static constexpr std::size_t kMaxSerializedCondition = 128;
|
||||
|
||||
/** Load a condition from its binary form
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ public:
|
||||
that were previously considered valid to no longer
|
||||
be allowed.
|
||||
*/
|
||||
static constexpr std::size_t kMAX_SERIALIZED_FULFILLMENT = 256;
|
||||
static constexpr std::size_t kMaxSerializedFulfillment = 256;
|
||||
|
||||
/** Load a fulfillment from its binary form
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ public:
|
||||
While future versions of this code will never lower
|
||||
this limit, they may opt to raise it.
|
||||
*/
|
||||
static constexpr std::size_t kMAX_PREIMAGE_LENGTH = 128;
|
||||
static constexpr std::size_t kMaxPreimageLength = 128;
|
||||
|
||||
/** Parse the payload for a PreimageSha256 condition
|
||||
|
||||
@@ -65,7 +65,7 @@ public:
|
||||
return {};
|
||||
}
|
||||
|
||||
if (s.size() > kMAX_PREIMAGE_LENGTH)
|
||||
if (s.size() > kMaxPreimageLength)
|
||||
{
|
||||
ec = Error::PreimageTooLong;
|
||||
return {};
|
||||
|
||||
@@ -6,7 +6,7 @@ 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 kCORO_STACK_SIZE = 1536 * 1024;
|
||||
constexpr std::size_t kCoroStackSize = 1536 * 1024;
|
||||
|
||||
template <class F>
|
||||
JobQueue::Coro::Coro(CoroCreateT, JobQueue& jq, JobType type, std::string name, F&& f)
|
||||
@@ -14,7 +14,7 @@ JobQueue::Coro::Coro(CoroCreateT, JobQueue& jq, JobType type, std::string name,
|
||||
, type_(type)
|
||||
, name_(std::move(name))
|
||||
, coro_(
|
||||
boost::context::protected_fixedsize_stack(kCORO_STACK_SIZE),
|
||||
boost::context::protected_fixedsize_stack(kCoroStackSize),
|
||||
[this, fn = std::forward<F>(f)](boost::coroutines2::coroutine<void>::push_type& doYield) {
|
||||
yield_ = &doYield;
|
||||
yield();
|
||||
|
||||
@@ -101,8 +101,8 @@ public:
|
||||
static JobTypes const&
|
||||
instance()
|
||||
{
|
||||
static JobTypes const kTYPES;
|
||||
return kTYPES;
|
||||
static JobTypes const kTypes;
|
||||
return kTypes;
|
||||
}
|
||||
|
||||
static std::string const&
|
||||
|
||||
@@ -67,7 +67,7 @@ public:
|
||||
[[nodiscard]] std::string
|
||||
getFormattedErrorMessages() const;
|
||||
|
||||
static constexpr unsigned kNEST_LIMIT{25};
|
||||
static constexpr unsigned kNestLimit{25};
|
||||
|
||||
private:
|
||||
enum class TokenType {
|
||||
|
||||
@@ -102,8 +102,8 @@ operator!=(StaticString x, std::string const& y)
|
||||
/** \brief Represents a <a HREF="http://www.json.org">JSON</a> value.
|
||||
*
|
||||
* This class is a discriminated union wrapper that can represent a:
|
||||
* - signed integer [range: Value::kMIN_INT - Value::kMAX_INT]
|
||||
* - unsigned integer (range: 0 - Value::kMAX_UINT)
|
||||
* - signed integer [range: Value::kMinInt - Value::kMaxInt]
|
||||
* - unsigned integer (range: 0 - Value::kMaxUInt)
|
||||
* - double
|
||||
* - UTF-8 string
|
||||
* - boolean
|
||||
@@ -138,10 +138,10 @@ public:
|
||||
using Int = json::Int;
|
||||
using ArrayIndex = UInt;
|
||||
|
||||
static Value const kNULL;
|
||||
static constexpr Int kMIN_INT = std::numeric_limits<Int>::min();
|
||||
static constexpr Int kMAX_INT = std::numeric_limits<Int>::max();
|
||||
static constexpr UInt kMAX_UINT = std::numeric_limits<UInt>::max();
|
||||
static Value const kNull;
|
||||
static constexpr Int kMinInt = std::numeric_limits<Int>::min();
|
||||
static constexpr Int kMaxInt = std::numeric_limits<Int>::max();
|
||||
static constexpr UInt kMaxUInt = std::numeric_limits<UInt>::max();
|
||||
|
||||
private:
|
||||
class CZString
|
||||
@@ -472,7 +472,7 @@ operator>=(Value const& x, Value const& y)
|
||||
class ValueAllocator
|
||||
{
|
||||
public:
|
||||
static constexpr auto kUNKNOWN = (unsigned)-1;
|
||||
static constexpr auto kUnknown = (unsigned)-1;
|
||||
|
||||
virtual ~ValueAllocator() = default;
|
||||
|
||||
@@ -481,7 +481,7 @@ public:
|
||||
virtual void
|
||||
releaseMemberName(char* memberName) = 0;
|
||||
virtual char*
|
||||
duplicateStringValue(char const* value, unsigned int length = kUNKNOWN) = 0;
|
||||
duplicateStringValue(char const* value, unsigned int length = kUnknown) = 0;
|
||||
virtual void
|
||||
releaseStringValue(char* value) = 0;
|
||||
};
|
||||
|
||||
@@ -24,7 +24,7 @@ struct CreateGenesisT
|
||||
{
|
||||
explicit CreateGenesisT() = default;
|
||||
};
|
||||
extern CreateGenesisT const kCREATE_GENESIS;
|
||||
extern CreateGenesisT const kCreateGenesis;
|
||||
|
||||
/** Holds a ledger.
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace xrpl {
|
||||
Values should not be duplicated.
|
||||
@see getNextLedgerTimeResolution
|
||||
*/
|
||||
std::chrono::seconds constexpr kLEDGER_POSSIBLE_TIME_RESOLUTIONS[] = {
|
||||
constexpr std::chrono::seconds kLedgerPossibleTimeResolutions[] = {
|
||||
std::chrono::seconds{10},
|
||||
std::chrono::seconds{20},
|
||||
std::chrono::seconds{30},
|
||||
@@ -21,16 +21,16 @@ std::chrono::seconds constexpr kLEDGER_POSSIBLE_TIME_RESOLUTIONS[] = {
|
||||
std::chrono::seconds{120}};
|
||||
|
||||
//! Initial resolution of ledger close time.
|
||||
auto constexpr kLEDGER_DEFAULT_TIME_RESOLUTION = kLEDGER_POSSIBLE_TIME_RESOLUTIONS[2];
|
||||
constexpr auto kLedgerDefaultTimeResolution = kLedgerPossibleTimeResolutions[2];
|
||||
|
||||
//! Close time resolution in genesis ledger
|
||||
auto constexpr kLEDGER_GENESIS_TIME_RESOLUTION = kLEDGER_POSSIBLE_TIME_RESOLUTIONS[0];
|
||||
constexpr auto kLedgerGenesisTimeResolution = kLedgerPossibleTimeResolutions[0];
|
||||
|
||||
//! How often we increase the close time resolution (in numbers of ledgers)
|
||||
auto constexpr kINCREASE_LEDGER_TIME_RESOLUTION_EVERY = 8;
|
||||
constexpr auto kIncreaseLedgerTimeResolutionEvery = 8;
|
||||
|
||||
//! How often we decrease the close time resolution (in numbers of ledgers)
|
||||
auto constexpr kDECREASE_LEDGER_TIME_RESOLUTION_EVERY = 1;
|
||||
constexpr auto kDecreaseLedgerTimeResolutionEvery = 1;
|
||||
|
||||
/** Calculates the close time resolution for the specified ledger.
|
||||
|
||||
@@ -46,7 +46,7 @@ auto constexpr kDECREASE_LEDGER_TIME_RESOLUTION_EVERY = 1;
|
||||
@param ledgerSeq the sequence number of the new ledger
|
||||
|
||||
@pre previousResolution must be a valid bin
|
||||
from @ref kLEDGER_POSSIBLE_TIME_RESOLUTIONS
|
||||
from @ref kLedgerPossibleTimeResolutions
|
||||
|
||||
@tparam Rep Type representing number of ticks in std::chrono::duration
|
||||
@tparam Period An std::ratio representing tick period in
|
||||
@@ -67,30 +67,30 @@ getNextLedgerTimeResolution(
|
||||
using namespace std::chrono;
|
||||
// Find the current resolution:
|
||||
auto iter = std::find(
|
||||
std::begin(kLEDGER_POSSIBLE_TIME_RESOLUTIONS),
|
||||
std::end(kLEDGER_POSSIBLE_TIME_RESOLUTIONS),
|
||||
std::begin(kLedgerPossibleTimeResolutions),
|
||||
std::end(kLedgerPossibleTimeResolutions),
|
||||
previousResolution);
|
||||
XRPL_ASSERT(
|
||||
iter != std::end(kLEDGER_POSSIBLE_TIME_RESOLUTIONS),
|
||||
iter != std::end(kLedgerPossibleTimeResolutions),
|
||||
"xrpl::getNextLedgerTimeResolution : found time resolution");
|
||||
|
||||
// This should never happen, but just as a precaution
|
||||
if (iter == std::end(kLEDGER_POSSIBLE_TIME_RESOLUTIONS))
|
||||
if (iter == std::end(kLedgerPossibleTimeResolutions))
|
||||
return previousResolution;
|
||||
|
||||
// If we did not previously agree, we try to decrease the resolution to
|
||||
// improve the chance that we will agree now.
|
||||
if (!previousAgree && (ledgerSeq % Seq{kDECREASE_LEDGER_TIME_RESOLUTION_EVERY} == Seq{0}))
|
||||
if (!previousAgree && (ledgerSeq % Seq{kDecreaseLedgerTimeResolutionEvery} == Seq{0}))
|
||||
{
|
||||
if (++iter != std::end(kLEDGER_POSSIBLE_TIME_RESOLUTIONS))
|
||||
if (++iter != std::end(kLedgerPossibleTimeResolutions))
|
||||
return *iter;
|
||||
}
|
||||
|
||||
// If we previously agreed, we try to increase the resolution to determine
|
||||
// if we can continue to agree.
|
||||
if (previousAgree && (ledgerSeq % Seq{kINCREASE_LEDGER_TIME_RESOLUTION_EVERY} == Seq{0}))
|
||||
if (previousAgree && (ledgerSeq % Seq{kIncreaseLedgerTimeResolutionEvery} == Seq{0}))
|
||||
{
|
||||
if (iter-- != std::begin(kLEDGER_POSSIBLE_TIME_RESOLUTIONS))
|
||||
if (iter-- != std::begin(kLedgerPossibleTimeResolutions))
|
||||
return *iter;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace xrpl {
|
||||
inline constexpr struct OpenLedgerT
|
||||
{
|
||||
explicit constexpr OpenLedgerT() = default;
|
||||
} kOPEN_LEDGER{};
|
||||
} kOpenLedger{};
|
||||
|
||||
/** Batch view construction tag.
|
||||
|
||||
@@ -33,7 +33,7 @@ inline constexpr struct OpenLedgerT
|
||||
inline constexpr struct BatchViewT
|
||||
{
|
||||
explicit constexpr BatchViewT() = default;
|
||||
} kBATCH_VIEW{};
|
||||
} kBatchView{};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
@@ -47,7 +47,7 @@ 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 kINITIAL_BUFFER_SIZE = kilobytes(256);
|
||||
static constexpr size_t kInitialBufferSize = kilobytes(256);
|
||||
|
||||
class TxsIterImpl;
|
||||
|
||||
@@ -139,7 +139,7 @@ public:
|
||||
std::shared_ptr<void const> hold = nullptr);
|
||||
|
||||
OpenView(OpenLedgerT, Rules const& rules, std::shared_ptr<ReadView const> const& base)
|
||||
: OpenView(kOPEN_LEDGER, &*base, rules, base)
|
||||
: OpenView(kOpenLedger, &*base, rules, base)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,11 @@
|
||||
|
||||
namespace xrpl {
|
||||
|
||||
// Forward declarations for SLE wrappers
|
||||
template <typename ViewT>
|
||||
class AccountRoot;
|
||||
using RAccountRoot = AccountRoot<ReadView>;
|
||||
|
||||
enum class SkipEntry : bool { No = false, Yes };
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
@@ -157,7 +162,7 @@ canWithdraw(
|
||||
ReadView const& view,
|
||||
AccountID const& from,
|
||||
AccountID const& to,
|
||||
SLE::const_ref toSle,
|
||||
RAccountRoot const& toWrapped,
|
||||
STAmount const& amount,
|
||||
bool hasDestinationTag);
|
||||
|
||||
|
||||
@@ -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 kINITIAL_BUFFER_SIZE = kilobytes(256);
|
||||
static constexpr size_t kInitialBufferSize = kilobytes(256);
|
||||
|
||||
RawStateTable()
|
||||
: monotonic_resource_{std::make_unique<boost::container::pmr::monotonic_buffer_resource>(
|
||||
kINITIAL_BUFFER_SIZE)}
|
||||
kInitialBufferSize)}
|
||||
, items_{monotonic_resource_.get()} {};
|
||||
|
||||
RawStateTable(RawStateTable const& rhs)
|
||||
: monotonic_resource_{std::make_unique<boost::container::pmr::monotonic_buffer_resource>(
|
||||
kINITIAL_BUFFER_SIZE)}
|
||||
kInitialBufferSize)}
|
||||
, items_{rhs.items_, monotonic_resource_.get()}
|
||||
, dropsDestroyed_{rhs.dropsDestroyed_} {};
|
||||
|
||||
|
||||
@@ -25,11 +25,11 @@ namespace detail {
|
||||
Number
|
||||
reduceOffer(auto const& amount)
|
||||
{
|
||||
static Number const kREDUCED_OFFER_PCT(9999, -4);
|
||||
static Number const kReducedOfferPct(9999, -4);
|
||||
|
||||
// Make sure the result is always less than amount or zero.
|
||||
NumberRoundModeGuard const mg(Number::RoundingMode::TowardsZero);
|
||||
return amount * kREDUCED_OFFER_PCT;
|
||||
return amount * kReducedOfferPct;
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
@@ -177,7 +177,7 @@ getAMMOfferStartWithTakerGets(
|
||||
Quality const& targetQuality,
|
||||
std::uint16_t const& tfee)
|
||||
{
|
||||
if (targetQuality.rate() == beast::kZERO)
|
||||
if (targetQuality.rate() == beast::kZero)
|
||||
return std::nullopt;
|
||||
|
||||
NumberRoundModeGuard const mg(Number::RoundingMode::ToNearest);
|
||||
@@ -244,7 +244,7 @@ getAMMOfferStartWithTakerPays(
|
||||
Quality const& targetQuality,
|
||||
std::uint16_t tfee)
|
||||
{
|
||||
if (targetQuality.rate() == beast::kZERO)
|
||||
if (targetQuality.rate() == beast::kZero)
|
||||
return std::nullopt;
|
||||
|
||||
NumberRoundModeGuard const mg(Number::RoundingMode::ToNearest);
|
||||
|
||||
@@ -2,8 +2,10 @@
|
||||
|
||||
#include <xrpl/basics/Expected.h>
|
||||
#include <xrpl/beast/utility/Journal.h>
|
||||
#include <xrpl/beast/utility/instrumentation.h>
|
||||
#include <xrpl/ledger/ApplyView.h>
|
||||
#include <xrpl/ledger/ReadView.h>
|
||||
#include <xrpl/ledger/helpers/SLEBase.h>
|
||||
#include <xrpl/protocol/Indexes.h>
|
||||
#include <xrpl/protocol/Rate.h>
|
||||
#include <xrpl/protocol/STLedgerEntry.h>
|
||||
@@ -15,46 +17,160 @@
|
||||
|
||||
namespace xrpl {
|
||||
|
||||
/** Check if the issuer has the global freeze flag set.
|
||||
@param issuer The account to check
|
||||
@return true if the account has global freeze set
|
||||
*/
|
||||
[[nodiscard]] bool
|
||||
isGlobalFrozen(ReadView const& view, AccountID const& issuer);
|
||||
|
||||
// Calculate liquid XRP balance for an account.
|
||||
// This function may be used to calculate the amount of XRP that
|
||||
// the holder is able to freely spend. It subtracts reserve requirements.
|
||||
//
|
||||
// ownerCountAdj adjusts the owner count in case the caller calculates
|
||||
// before ledger entries are added or removed. Positive to add, negative
|
||||
// to subtract.
|
||||
//
|
||||
// @param ownerCountAdj positive to add to count, negative to reduce count.
|
||||
[[nodiscard]] XRPAmount
|
||||
xrpLiquid(ReadView const& view, AccountID const& id, std::int32_t ownerCountAdj, beast::Journal j);
|
||||
|
||||
/** Adjust the owner count up or down. */
|
||||
void
|
||||
adjustOwnerCount(
|
||||
ApplyView& view,
|
||||
std::shared_ptr<SLE> const& sle,
|
||||
std::int32_t amount,
|
||||
beast::Journal j);
|
||||
|
||||
/** Returns IOU issuer transfer fee as Rate. Rate specifies
|
||||
* the fee as fractions of 1 billion. For example, 1% transfer rate
|
||||
* is represented as 1,010,000,000.
|
||||
* @param issuer The IOU issuer
|
||||
/**
|
||||
* View-parameterized wrapper for AccountRoot ledger entries.
|
||||
*
|
||||
* AccountRoot<ReadView> — read-only access to account data
|
||||
* AccountRoot<ApplyView> — read-write access, with insert/update/erase
|
||||
* and domain-specific write methods
|
||||
*/
|
||||
[[nodiscard]] Rate
|
||||
transferRate(ReadView const& view, AccountID const& issuer);
|
||||
template <typename ViewT>
|
||||
class AccountRoot : public SLEBase<ViewT>
|
||||
{
|
||||
static constexpr bool kIsWritable = SLEBase<ViewT>::kIsWritable;
|
||||
|
||||
AccountID const id_;
|
||||
|
||||
public:
|
||||
/** Constructor for read-only context */
|
||||
AccountRoot(
|
||||
AccountID const& id,
|
||||
ReadView const& view,
|
||||
beast::Journal j = beast::Journal{beast::Journal::getNullSink()})
|
||||
requires(!kIsWritable)
|
||||
: SLEBase<ViewT>(view.read(keylet::account(id)), view, j), id_(id)
|
||||
{
|
||||
}
|
||||
|
||||
/** Constructor for writable context */
|
||||
AccountRoot(
|
||||
AccountID const& id,
|
||||
ApplyView& view,
|
||||
beast::Journal j = beast::Journal{beast::Journal::getNullSink()})
|
||||
requires kIsWritable
|
||||
: SLEBase<ViewT>(keylet::account(id), view, j), id_(id)
|
||||
{
|
||||
}
|
||||
|
||||
/** Converting constructor: writable → read-only. */
|
||||
template <WritableView OtherViewT>
|
||||
AccountRoot(AccountRoot<OtherViewT> const& other)
|
||||
requires(!kIsWritable)
|
||||
: SLEBase<ViewT>(other), id_(other.id())
|
||||
{
|
||||
}
|
||||
|
||||
/** Create an AccountRoot backed by a brand-new SLE.
|
||||
*/
|
||||
[[nodiscard]] static AccountRoot
|
||||
makeNew(
|
||||
AccountID const& id,
|
||||
ApplyView& view,
|
||||
beast::Journal j = beast::Journal{beast::Journal::getNullSink()})
|
||||
requires kIsWritable
|
||||
{
|
||||
return AccountRoot(id, view, j, std::make_shared<SLE>(keylet::account(id)));
|
||||
}
|
||||
|
||||
[[nodiscard]] AccountID const&
|
||||
id() const
|
||||
{
|
||||
return id_;
|
||||
}
|
||||
|
||||
// --- Read-only domain methods (available on both specializations) ---
|
||||
|
||||
/** Check if the issuer has the global freeze flag set.
|
||||
@return true if the account has global freeze set
|
||||
*/
|
||||
[[nodiscard]] bool
|
||||
isGlobalFrozen() const;
|
||||
|
||||
/** Returns IOU issuer transfer fee as Rate. Rate specifies
|
||||
* the fee as fractions of 1 billion. For example, 1% transfer rate
|
||||
* is represented as 1,010,000,000.
|
||||
*/
|
||||
[[nodiscard]] Rate
|
||||
transferRate() const;
|
||||
|
||||
// Calculate liquid XRP balance for an account.
|
||||
// This function may be used to calculate the amount of XRP that
|
||||
// the holder is able to freely spend. It subtracts reserve requirements.
|
||||
//
|
||||
// ownerCountAdj adjusts the owner count in case the caller calculates
|
||||
// before ledger entries are added or removed. Positive to add, negative
|
||||
// to subtract.
|
||||
//
|
||||
// @param ownerCountAdj positive to add to count, negative to reduce count.
|
||||
[[nodiscard]] XRPAmount
|
||||
xrpLiquid(std::int32_t ownerCountAdj) const;
|
||||
|
||||
/** Checks the destination and tag.
|
||||
|
||||
- Checks that the SLE is not null.
|
||||
- If the SLE requires a destination tag, checks that there is a tag.
|
||||
*/
|
||||
[[nodiscard]] TER
|
||||
checkDestinationAndTag(bool hasDestinationTag) const;
|
||||
|
||||
/** Returns true if and only if sleAcct is a pseudo-account or specific
|
||||
pseudo-accounts in pseudoFieldFilter.
|
||||
|
||||
Returns false if sleAcct is:
|
||||
- NOT a pseudo-account OR
|
||||
- NOT a ltACCOUNT_ROOT OR
|
||||
- null pointer
|
||||
*/
|
||||
[[nodiscard]] bool
|
||||
isPseudoAccount(std::set<SField const*> const& pseudoFieldFilter = {}) const;
|
||||
|
||||
[[nodiscard]] bool
|
||||
operator==(AccountRoot const& other) const
|
||||
{
|
||||
return id_ == other.id_;
|
||||
}
|
||||
|
||||
[[nodiscard]] bool
|
||||
operator==(AccountID const& other) const
|
||||
{
|
||||
return id_ == other;
|
||||
}
|
||||
|
||||
// --- Write-only domain methods (compile-time gated) ---
|
||||
|
||||
/** Adjust the owner count up or down. */
|
||||
void
|
||||
adjustOwnerCount(std::int32_t amount)
|
||||
requires kIsWritable;
|
||||
|
||||
private:
|
||||
// Private constructor only used by `makeNew`
|
||||
AccountRoot(AccountID const& id, ApplyView& view, beast::Journal j, std::shared_ptr<SLE> sle)
|
||||
requires kIsWritable
|
||||
: SLEBase<ViewT>(std::move(sle), view, j), id_(id)
|
||||
{
|
||||
this->insert();
|
||||
}
|
||||
};
|
||||
|
||||
// CTAD deduction guide — bare AccountRoot(id, view) always deduces read-only.
|
||||
// For writable access, use WAccountRoot(id, applyView) explicitly.
|
||||
AccountRoot(AccountID const&, ReadView const&) -> AccountRoot<ReadView>;
|
||||
AccountRoot(AccountID const&, ReadView const&, beast::Journal) -> AccountRoot<ReadView>;
|
||||
|
||||
// Backward-compatible aliases
|
||||
using RAccountRoot = AccountRoot<ReadView>;
|
||||
using WAccountRoot = AccountRoot<ApplyView>;
|
||||
|
||||
// Explicit instantiation declarations (definitions in .cpp)
|
||||
extern template class AccountRoot<ReadView>;
|
||||
extern template class AccountRoot<ApplyView>;
|
||||
|
||||
/** Generate a pseudo-account address from a pseudo owner key.
|
||||
@param pseudoOwnerKey The key to generate the address from
|
||||
@return The generated account ID
|
||||
*/
|
||||
AccountID
|
||||
[[nodiscard]] AccountID
|
||||
pseudoAccountAddress(ReadView const& view, uint256 const& pseudoOwnerKey);
|
||||
|
||||
/** Returns the list of fields that define an ACCOUNT_ROOT as a pseudo-account
|
||||
@@ -67,29 +183,6 @@ pseudoAccountAddress(ReadView const& view, uint256 const& pseudoOwnerKey);
|
||||
[[nodiscard]] std::vector<SField const*> const&
|
||||
getPseudoAccountFields();
|
||||
|
||||
/** Returns true if and only if sleAcct is a pseudo-account or specific
|
||||
pseudo-accounts in pseudoFieldFilter.
|
||||
|
||||
Returns false if sleAcct is:
|
||||
- NOT a pseudo-account OR
|
||||
- NOT a ltACCOUNT_ROOT OR
|
||||
- null pointer
|
||||
*/
|
||||
[[nodiscard]] bool
|
||||
isPseudoAccount(
|
||||
std::shared_ptr<SLE const> sleAcct,
|
||||
std::set<SField const*> const& pseudoFieldFilter = {});
|
||||
|
||||
/** Convenience overload that reads the account from the view. */
|
||||
[[nodiscard]] inline bool
|
||||
isPseudoAccount(
|
||||
ReadView const& view,
|
||||
AccountID const& accountId,
|
||||
std::set<SField const*> const& pseudoFieldFilter = {})
|
||||
{
|
||||
return isPseudoAccount(view.read(keylet::account(accountId)), pseudoFieldFilter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create pseudo-account, storing pseudoOwnerKey into ownerField.
|
||||
*
|
||||
@@ -101,12 +194,4 @@ isPseudoAccount(
|
||||
[[nodiscard]] Expected<std::shared_ptr<SLE>, TER>
|
||||
createPseudoAccount(ApplyView& view, uint256 const& pseudoOwnerKey, SField const& ownerField);
|
||||
|
||||
/** Checks the destination and tag.
|
||||
|
||||
- Checks that the SLE is not null.
|
||||
- If the SLE requires a destination tag, checks that there is a tag.
|
||||
*/
|
||||
[[nodiscard]] TER
|
||||
checkDestinationAndTag(SLE::const_ref toSle, bool hasDestinationTag);
|
||||
|
||||
} // namespace xrpl
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <xrpl/beast/utility/Journal.h>
|
||||
#include <xrpl/ledger/ApplyView.h>
|
||||
#include <xrpl/ledger/ReadView.h>
|
||||
#include <xrpl/ledger/helpers/AccountRootHelpers.h>
|
||||
#include <xrpl/protocol/AccountID.h>
|
||||
#include <xrpl/protocol/STArray.h>
|
||||
#include <xrpl/protocol/STTx.h>
|
||||
@@ -69,8 +70,7 @@ verifyDepositPreauth(
|
||||
STTx const& tx,
|
||||
ApplyView& view,
|
||||
AccountID const& src,
|
||||
AccountID const& dst,
|
||||
std::shared_ptr<SLE const> const& sleDst,
|
||||
RAccountRoot const& dst,
|
||||
beast::Journal j);
|
||||
|
||||
} // namespace xrpl
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
#include <xrpl/protocol/MPTAmount.h>
|
||||
#include <xrpl/protocol/Rate.h>
|
||||
|
||||
#include <variant>
|
||||
|
||||
namespace xrpl {
|
||||
|
||||
template <ValidIssueType T>
|
||||
@@ -18,7 +20,7 @@ TER
|
||||
escrowUnlockApplyHelper(
|
||||
ApplyView& view,
|
||||
Rate lockedRate,
|
||||
std::shared_ptr<SLE> const& sleDest,
|
||||
std::variant<std::shared_ptr<SLE>, WAccountRoot> dest,
|
||||
STAmount const& xrpBalance,
|
||||
STAmount const& amount,
|
||||
AccountID const& issuer,
|
||||
@@ -32,7 +34,7 @@ inline TER
|
||||
escrowUnlockApplyHelper<Issue>(
|
||||
ApplyView& view,
|
||||
Rate lockedRate,
|
||||
std::shared_ptr<SLE> const& sleDest,
|
||||
std::variant<std::shared_ptr<SLE>, WAccountRoot> dest,
|
||||
STAmount const& xrpBalance,
|
||||
STAmount const& amount,
|
||||
AccountID const& issuer,
|
||||
@@ -55,8 +57,14 @@ escrowUnlockApplyHelper<Issue>(
|
||||
|
||||
if (!view.exists(trustLineKey) && createAsset)
|
||||
{
|
||||
// For backwards compatibility: if dest is not WAccountRoot, return error
|
||||
if (!std::holds_alternative<WAccountRoot>(dest))
|
||||
return tefEXCEPTION;
|
||||
|
||||
auto& wrappedDest = std::get<WAccountRoot>(dest);
|
||||
|
||||
// Can the account cover the trust line's reserve?
|
||||
if (std::uint32_t const ownerCount = {sleDest->at(sfOwnerCount)};
|
||||
if (std::uint32_t const ownerCount = {wrappedDest->at(sfOwnerCount)};
|
||||
xrpBalance < view.fees().accountReserve(ownerCount + 1))
|
||||
{
|
||||
JLOG(journal.trace()) << "Trust line does not exist. "
|
||||
@@ -69,28 +77,28 @@ escrowUnlockApplyHelper<Issue>(
|
||||
STAmount initialBalance(issue);
|
||||
initialBalance.get<Issue>().account = noAccount();
|
||||
|
||||
if (TER const ter = trustCreate(
|
||||
view, // payment sandbox
|
||||
recvLow, // is dest low?
|
||||
issuer, // source
|
||||
receiver, // destination
|
||||
trustLineKey.key, // ledger index
|
||||
sleDest, // Account to add to
|
||||
false, // authorize account
|
||||
(sleDest->getFlags() & lsfDefaultRipple) == 0, //
|
||||
false, // freeze trust line
|
||||
false, // deep freeze trust line
|
||||
initialBalance, // zero initial balance
|
||||
Issue(currency, receiver), // limit of zero
|
||||
0, // quality in
|
||||
0, // quality out
|
||||
journal); // journal
|
||||
if (TER const ter = WIOUIssuance(view, issue, journal)
|
||||
.trustCreate(
|
||||
recvLow, // is dest low?
|
||||
issuer, // source
|
||||
receiver, // destination
|
||||
trustLineKey.key, // ledger index
|
||||
wrappedDest, // Account to add to
|
||||
false, // authorize account
|
||||
!wrappedDest->isFlag(lsfDefaultRipple),
|
||||
false, // freeze trust line
|
||||
false, // deep freeze trust line
|
||||
initialBalance, // zero initial balance
|
||||
Issue(currency, receiver), // limit of zero
|
||||
0, // quality in
|
||||
0, // quality out
|
||||
journal); // journal
|
||||
!isTesSuccess(ter))
|
||||
{
|
||||
return ter; // LCOV_EXCL_LINE
|
||||
}
|
||||
|
||||
view.update(sleDest);
|
||||
wrappedDest.update();
|
||||
}
|
||||
|
||||
if (!view.exists(trustLineKey) && !receiverIssuer)
|
||||
@@ -111,7 +119,7 @@ escrowUnlockApplyHelper<Issue>(
|
||||
// whereas in a normal payment, the transfer fee is taken on top of the
|
||||
// sending amount.
|
||||
auto finalAmt = amount;
|
||||
if ((!senderIssuer && !receiverIssuer) && lockedRate != kPARITY_RATE)
|
||||
if ((!senderIssuer && !receiverIssuer) && lockedRate != kParityRate)
|
||||
{
|
||||
// compute transfer fee, if any
|
||||
auto const xferFee =
|
||||
@@ -162,7 +170,7 @@ inline TER
|
||||
escrowUnlockApplyHelper<MPTIssue>(
|
||||
ApplyView& view,
|
||||
Rate lockedRate,
|
||||
std::shared_ptr<SLE> const& sleDest,
|
||||
std::variant<std::shared_ptr<SLE>, WAccountRoot> dest,
|
||||
STAmount const& xrpBalance,
|
||||
STAmount const& amount,
|
||||
AccountID const& issuer,
|
||||
@@ -178,19 +186,26 @@ escrowUnlockApplyHelper<MPTIssue>(
|
||||
auto const issuanceKey = keylet::mptIssuance(mptID);
|
||||
if (!view.exists(keylet::mptoken(issuanceKey.key, receiver)) && createAsset && !receiverIssuer)
|
||||
{
|
||||
if (std::uint32_t const ownerCount = {sleDest->at(sfOwnerCount)};
|
||||
// For backwards compatibility: if dest is not WAccountRoot, return error
|
||||
if (!std::holds_alternative<WAccountRoot>(dest))
|
||||
return tefEXCEPTION;
|
||||
|
||||
auto& wrappedDest = std::get<WAccountRoot>(dest);
|
||||
|
||||
if (std::uint32_t const ownerCount = {wrappedDest->at(sfOwnerCount)};
|
||||
xrpBalance < view.fees().accountReserve(ownerCount + 1))
|
||||
{
|
||||
return tecINSUFFICIENT_RESERVE;
|
||||
}
|
||||
|
||||
if (auto const ter = createMPToken(view, mptID, receiver, 0); !isTesSuccess(ter))
|
||||
if (auto const ter = WMPTokenIssuance(view, mptID, journal).createMPToken(receiver, 0);
|
||||
!isTesSuccess(ter))
|
||||
{
|
||||
return ter; // LCOV_EXCL_LINE
|
||||
}
|
||||
|
||||
// update owner count.
|
||||
adjustOwnerCount(view, sleDest, 1, journal);
|
||||
wrappedDest.adjustOwnerCount(1);
|
||||
}
|
||||
|
||||
if (!view.exists(keylet::mptoken(issuanceKey.key, receiver)) && !receiverIssuer)
|
||||
@@ -211,20 +226,20 @@ escrowUnlockApplyHelper<MPTIssue>(
|
||||
// whereas in a normal payment, the transfer fee is taken on top of the
|
||||
// sending amount.
|
||||
auto finalAmt = amount;
|
||||
if ((!senderIssuer && !receiverIssuer) && lockedRate != kPARITY_RATE)
|
||||
if ((!senderIssuer && !receiverIssuer) && lockedRate != kParityRate)
|
||||
{
|
||||
// compute transfer fee, if any
|
||||
auto const xferFee = amount.value() - divideRound(amount, lockedRate, amount.asset(), true);
|
||||
// compute balance to transfer
|
||||
finalAmt = amount.value() - xferFee;
|
||||
}
|
||||
return unlockEscrowMPT(
|
||||
view,
|
||||
sender,
|
||||
receiver,
|
||||
finalAmt,
|
||||
view.rules().enabled(fixTokenEscrowV1) ? amount : finalAmt,
|
||||
journal);
|
||||
return WMPTokenIssuance(view, amount.get<MPTIssue>(), journal)
|
||||
.unlockEscrow(
|
||||
sender,
|
||||
receiver,
|
||||
finalAmt,
|
||||
view.rules().enabled(fixTokenEscrowV1) ? amount : finalAmt,
|
||||
journal);
|
||||
}
|
||||
|
||||
} // namespace xrpl
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace xrpl {
|
||||
bool
|
||||
checkLendingProtocolDependencies(Rules const& rules, STTx const& tx);
|
||||
|
||||
static constexpr std::uint32_t kSECONDS_IN_YEAR = 365 * 24 * 60 * 60;
|
||||
static constexpr std::uint32_t kSecondsInYear = 365 * 24 * 60 * 60;
|
||||
|
||||
Number
|
||||
loanPeriodicRate(TenthBips32 interestRate, std::uint32_t paymentInterval);
|
||||
@@ -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 = kNUM_ZERO;
|
||||
Number principalPaid = kNumZero;
|
||||
|
||||
// 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 = kNUM_ZERO;
|
||||
Number interestPaid = kNumZero;
|
||||
|
||||
// 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 = kNUM_ZERO;
|
||||
Number valueChange = kNumZero;
|
||||
|
||||
/* 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 = kNUM_ZERO;
|
||||
Number feePaid = kNumZero;
|
||||
|
||||
LoanPaymentParts&
|
||||
operator+=(LoanPaymentParts const& other);
|
||||
@@ -161,7 +161,7 @@ adjustImpreciseNumber(
|
||||
{
|
||||
value = roundToAsset(asset, value + adjustment, vaultScale);
|
||||
|
||||
if (*value < beast::kZERO)
|
||||
if (*value < beast::kZero)
|
||||
value = 0;
|
||||
}
|
||||
|
||||
@@ -169,7 +169,7 @@ inline int
|
||||
getAssetsTotalScale(SLE::const_ref vaultSle)
|
||||
{
|
||||
if (!vaultSle)
|
||||
return Number::kMIN_EXPONENT - 1; // LCOV_EXCL_LINE
|
||||
return Number::kMinExponent - 1; // LCOV_EXCL_LINE
|
||||
return scale(vaultSle->at(sfAssetsTotal), vaultSle->at(sfAsset));
|
||||
}
|
||||
|
||||
@@ -311,7 +311,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 = kNUM_ZERO)
|
||||
ExtendedPaymentComponents(PaymentComponents const& p, Number fee, Number interest = kNumZero)
|
||||
: PaymentComponents(p)
|
||||
, untrackedManagementFee(fee)
|
||||
, untrackedInterest(interest)
|
||||
@@ -487,4 +487,15 @@ loanMakePayment(
|
||||
LoanPaymentType const paymentType,
|
||||
beast::Journal j);
|
||||
|
||||
// LoanBroker-specific `adjustOwnerCount` function (temporary, while the Wrapped classes are WIP)
|
||||
// Assert will check the type, so that we ensure it's not used by anything else
|
||||
// Order of parameters is different from the old `adjustOwnerCount` function to avoid anything
|
||||
// accidentally calling this with the wrong type.
|
||||
void
|
||||
adjustOwnerCount(
|
||||
std::shared_ptr<SLE> const& sle,
|
||||
ApplyView& view,
|
||||
std::int32_t amount,
|
||||
beast::Journal j);
|
||||
|
||||
} // namespace xrpl
|
||||
|
||||
@@ -3,117 +3,297 @@
|
||||
#include <xrpl/beast/utility/Journal.h>
|
||||
#include <xrpl/ledger/ApplyView.h>
|
||||
#include <xrpl/ledger/ReadView.h>
|
||||
#include <xrpl/ledger/helpers/SLEBase.h>
|
||||
#include <xrpl/ledger/helpers/TokenHelpers.h>
|
||||
#include <xrpl/protocol/Indexes.h>
|
||||
#include <xrpl/protocol/MPTIssue.h>
|
||||
#include <xrpl/protocol/Rate.h>
|
||||
#include <xrpl/protocol/STAmount.h>
|
||||
#include <xrpl/protocol/TER.h>
|
||||
#include <xrpl/protocol/XRPAmount.h>
|
||||
|
||||
#include <initializer_list>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
|
||||
namespace xrpl {
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//
|
||||
// Freeze checking (MPT-specific)
|
||||
// MPTokenIssuance ledger entry wrapper (view-parameterized)
|
||||
//
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
[[nodiscard]] bool
|
||||
isGlobalFrozen(ReadView const& view, MPTIssue const& mptIssue);
|
||||
|
||||
[[nodiscard]] bool
|
||||
isIndividualFrozen(ReadView const& view, AccountID const& account, MPTIssue const& mptIssue);
|
||||
|
||||
[[nodiscard]] bool
|
||||
isFrozen(ReadView const& view, AccountID const& account, MPTIssue const& mptIssue, int depth = 0);
|
||||
|
||||
[[nodiscard]] bool
|
||||
isAnyFrozen(
|
||||
ReadView const& view,
|
||||
std::initializer_list<AccountID> const& accounts,
|
||||
MPTIssue const& mptIssue,
|
||||
int depth = 0);
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//
|
||||
// Transfer rate (MPT-specific)
|
||||
//
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/** Returns MPT transfer fee as Rate. Rate specifies
|
||||
* the fee as fractions of 1 billion. For example, 1% transfer rate
|
||||
* is represented as 1,010,000,000.
|
||||
* @param issuanceID MPTokenIssuanceID of MPTTokenIssuance object
|
||||
*/
|
||||
[[nodiscard]] Rate
|
||||
transferRate(ReadView const& view, MPTID const& issuanceID);
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//
|
||||
// Holding checks (MPT-specific)
|
||||
//
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
[[nodiscard]] TER
|
||||
canAddHolding(ReadView const& view, MPTIssue const& mptIssue);
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//
|
||||
// Authorization (MPT-specific)
|
||||
//
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
[[nodiscard]] TER
|
||||
authorizeMPToken(
|
||||
ApplyView& view,
|
||||
XRPAmount const& priorBalance,
|
||||
MPTID const& mptIssuanceID,
|
||||
AccountID const& account,
|
||||
beast::Journal journal,
|
||||
std::uint32_t flags = 0,
|
||||
std::optional<AccountID> holderID = std::nullopt);
|
||||
|
||||
/** Check if the account lacks required authorization for MPT.
|
||||
/**
|
||||
* View-parameterized wrapper for MPTokenIssuance ledger entries.
|
||||
*
|
||||
* requireAuth check is recursive for MPT shares in a vault, descending to
|
||||
* assets in the vault, up to maxAssetCheckDepth recursion depth. This is
|
||||
* purely defensive, as we currently do not allow such vaults to be created.
|
||||
* WeakAuth intentionally allows missing MPTokens under MPToken V2.
|
||||
*/
|
||||
[[nodiscard]] TER
|
||||
requireAuth(
|
||||
ReadView const& view,
|
||||
MPTIssue const& mptIssue,
|
||||
AccountID const& account,
|
||||
AuthType authType = AuthType::Legacy,
|
||||
int depth = 0);
|
||||
|
||||
/** Enforce account has MPToken to match its authorization.
|
||||
* MPTokenIssuance<ReadView> — read-only access to issuance data
|
||||
* MPTokenIssuance<ApplyView> — read-write access, with insert/update/erase
|
||||
* and domain-specific write methods
|
||||
*
|
||||
* Called from doApply - it will check for expired (and delete if found any)
|
||||
* credentials matching DomainID set in MPTokenIssuance. Must be called if
|
||||
* requireAuth(...MPTIssue...) returned tesSUCCESS or tecEXPIRED in preclaim.
|
||||
* Carries the MPTID and MPTIssue alongside the SLE so callers don't need to
|
||||
* thread them through every method call.
|
||||
*/
|
||||
[[nodiscard]] TER
|
||||
enforceMPTokenAuthorization(
|
||||
ApplyView& view,
|
||||
MPTID const& mptIssuanceID,
|
||||
AccountID const& account,
|
||||
XRPAmount const& priorBalance,
|
||||
beast::Journal j);
|
||||
template <typename ViewT>
|
||||
class MPTokenIssuance : public SLEBase<ViewT>, public TokenBase<ViewT>
|
||||
{
|
||||
static constexpr bool kIsWritable = SLEBase<ViewT>::kIsWritable;
|
||||
|
||||
/** Check if the destination account is allowed
|
||||
* to receive MPT. Return tecNO_AUTH if it doesn't
|
||||
* and tesSUCCESS otherwise.
|
||||
*/
|
||||
[[nodiscard]] TER
|
||||
canTransfer(
|
||||
ReadView const& view,
|
||||
MPTIssue const& mptIssue,
|
||||
AccountID const& from,
|
||||
AccountID const& to);
|
||||
MPTID const mptID_;
|
||||
MPTIssue const mptIssue_;
|
||||
|
||||
public:
|
||||
/** Constructor for read-only context (MPTIssue) */
|
||||
MPTokenIssuance(
|
||||
ReadView const& view,
|
||||
MPTIssue const& mptIssue,
|
||||
beast::Journal j = beast::Journal{beast::Journal::getNullSink()})
|
||||
requires(!kIsWritable)
|
||||
: SLEBase<ViewT>(view.read(keylet::mptIssuance(mptIssue.getMptID())), view, j)
|
||||
, mptID_(mptIssue.getMptID())
|
||||
, mptIssue_(mptIssue)
|
||||
{
|
||||
}
|
||||
|
||||
/** Constructor for read-only context (MPTID) */
|
||||
MPTokenIssuance(
|
||||
ReadView const& view,
|
||||
MPTID const& mptID,
|
||||
beast::Journal j = beast::Journal{beast::Journal::getNullSink()})
|
||||
requires(!kIsWritable)
|
||||
: SLEBase<ViewT>(view.read(keylet::mptIssuance(mptID)), view, j)
|
||||
, mptID_(mptID)
|
||||
, mptIssue_(MPTIssue(mptID))
|
||||
{
|
||||
}
|
||||
|
||||
/** Constructor for writable context (MPTIssue) */
|
||||
MPTokenIssuance(
|
||||
ApplyView& view,
|
||||
MPTIssue const& mptIssue,
|
||||
beast::Journal j = beast::Journal{beast::Journal::getNullSink()})
|
||||
requires kIsWritable
|
||||
: SLEBase<ViewT>(keylet::mptIssuance(mptIssue.getMptID()), view, j)
|
||||
, mptID_(mptIssue.getMptID())
|
||||
, mptIssue_(mptIssue)
|
||||
{
|
||||
}
|
||||
|
||||
/** Constructor for writable context (MPTID) */
|
||||
MPTokenIssuance(
|
||||
ApplyView& view,
|
||||
MPTID const& mptID,
|
||||
beast::Journal j = beast::Journal{beast::Journal::getNullSink()})
|
||||
requires kIsWritable
|
||||
: SLEBase<ViewT>(keylet::mptIssuance(mptID), view, j)
|
||||
, mptID_(mptID)
|
||||
, mptIssue_(MPTIssue(mptID))
|
||||
{
|
||||
}
|
||||
|
||||
/** Converting constructor: writable → read-only. */
|
||||
template <WritableView OtherViewT>
|
||||
MPTokenIssuance(MPTokenIssuance<OtherViewT> const& other)
|
||||
requires(!kIsWritable)
|
||||
: SLEBase<ViewT>(other), mptID_(other.getMptID()), mptIssue_(other.getMptIssue())
|
||||
{
|
||||
}
|
||||
|
||||
/** Create an MPTokenIssuance backed by a brand-new SLE (already inserted into
|
||||
* the view).
|
||||
*/
|
||||
[[nodiscard]] static MPTokenIssuance
|
||||
makeNew(
|
||||
MPTID const& mptID,
|
||||
ApplyView& view,
|
||||
beast::Journal j = beast::Journal{beast::Journal::getNullSink()})
|
||||
requires kIsWritable
|
||||
{
|
||||
return MPTokenIssuance(mptID, view, j, std::make_shared<SLE>(keylet::mptIssuance(mptID)));
|
||||
}
|
||||
|
||||
[[nodiscard]] static MPTokenIssuance
|
||||
makeNew(
|
||||
std::uint32_t const seq,
|
||||
AccountID const& issuer,
|
||||
ApplyView& view,
|
||||
beast::Journal j = beast::Journal{beast::Journal::getNullSink()})
|
||||
requires kIsWritable
|
||||
{
|
||||
auto const mptID = makeMptID(seq, issuer);
|
||||
return MPTokenIssuance(mptID, view, j, std::make_shared<SLE>(keylet::mptIssuance(mptID)));
|
||||
}
|
||||
|
||||
// --- Inline accessors ---
|
||||
|
||||
[[nodiscard]] MPTID const&
|
||||
getMptID() const
|
||||
{
|
||||
return mptID_;
|
||||
}
|
||||
|
||||
[[nodiscard]] MPTIssue const&
|
||||
getMptIssue() const
|
||||
{
|
||||
return mptIssue_;
|
||||
}
|
||||
|
||||
[[nodiscard]] AccountID const&
|
||||
getIssuer() const
|
||||
{
|
||||
return mptIssue_.getIssuer();
|
||||
}
|
||||
|
||||
// --- Read-only domain methods (available on both specializations) ---
|
||||
|
||||
[[nodiscard]] bool
|
||||
isGlobalFrozen() const override;
|
||||
|
||||
[[nodiscard]] bool
|
||||
isIndividualFrozen(AccountID const& account) const override;
|
||||
|
||||
/**
|
||||
* isFrozen check is recursive for MPT shares in a vault, descending to
|
||||
* assets in the vault, up to kMaxAssetCheckDepth recursion depth. This is
|
||||
* purely defensive, as we currently do not allow such vaults to be created.
|
||||
*/
|
||||
[[nodiscard]] bool
|
||||
isFrozen(AccountID const& account, int depth = 0) const override;
|
||||
|
||||
[[nodiscard]] bool
|
||||
isAnyFrozen(std::initializer_list<AccountID> const& accounts, int depth = 0) const;
|
||||
|
||||
/** Returns MPT transfer fee as Rate. */
|
||||
[[nodiscard]] Rate
|
||||
transferRate() const override;
|
||||
|
||||
[[nodiscard]] TER
|
||||
canAddHolding() const;
|
||||
|
||||
/** Check if the account lacks required authorization for MPT. */
|
||||
[[nodiscard]] TER
|
||||
requireAuth(AccountID const& account, AuthType authType = AuthType::Legacy, int depth = 0)
|
||||
const override;
|
||||
|
||||
/** Check if `from` is allowed to send MPT to `to`. */
|
||||
[[nodiscard]] TER
|
||||
canTransfer(AccountID const& from, AccountID const& to) const override;
|
||||
|
||||
/** Check if the token requires authorization for holders. */
|
||||
[[nodiscard]] bool
|
||||
requiresAuth() const override;
|
||||
|
||||
/** Check if the token issuer has enabled clawback capability. */
|
||||
[[nodiscard]] bool
|
||||
canClawback() const override;
|
||||
|
||||
// --- Write-only domain methods (compile-time gated) ---
|
||||
|
||||
[[nodiscard]] TER
|
||||
addEmptyHolding(AccountID const& accountID, XRPAmount priorBalance, beast::Journal journal)
|
||||
requires kIsWritable;
|
||||
|
||||
[[nodiscard]] TER
|
||||
removeEmptyHolding(AccountID const& accountID, beast::Journal journal)
|
||||
requires kIsWritable;
|
||||
|
||||
[[nodiscard]] TER
|
||||
authorizeMPToken(
|
||||
XRPAmount const& priorBalance,
|
||||
AccountID const& account,
|
||||
beast::Journal journal,
|
||||
std::uint32_t flags = 0,
|
||||
std::optional<AccountID> holderID = std::nullopt)
|
||||
requires kIsWritable;
|
||||
|
||||
/** Enforce account has MPToken to match its authorization.
|
||||
*
|
||||
* Called from doApply - it will check for expired (and delete if found any)
|
||||
* credentials matching DomainID set in MPTokenIssuance. Must be called if
|
||||
* requireAuth(...) returned tesSUCCESS or tecEXPIRED in preclaim.
|
||||
*/
|
||||
[[nodiscard]] TER
|
||||
enforceMPTokenAuthorization(
|
||||
AccountID const& account,
|
||||
XRPAmount const& priorBalance,
|
||||
beast::Journal j)
|
||||
requires kIsWritable;
|
||||
|
||||
// --- Amount accessors ---
|
||||
|
||||
/** Maximum amount allowed for this issuance (sfMaximumAmount or default). */
|
||||
[[nodiscard]] std::int64_t
|
||||
maxAmount() const;
|
||||
|
||||
/** Available amount = maxAmount - OutstandingAmount.
|
||||
* Throws if the issuance SLE does not exist.
|
||||
*/
|
||||
[[nodiscard]] std::int64_t
|
||||
availableAmount() const;
|
||||
|
||||
/** Funds available for the issuer to sell in an issuer-owned offer. */
|
||||
[[nodiscard]] STAmount
|
||||
issuerFundsToSelfIssue() const;
|
||||
|
||||
// --- Holder MPToken management (writable) ---
|
||||
|
||||
/** Create a holder-side MPToken for `account` under this issuance. */
|
||||
[[nodiscard]] TER
|
||||
createMPToken(AccountID const& account, std::uint32_t flags)
|
||||
requires kIsWritable;
|
||||
|
||||
/** Ensure `holder` has an MPToken under this issuance, creating one if needed. */
|
||||
[[nodiscard]] TER
|
||||
checkCreateMPT(AccountID const& holder, beast::Journal j)
|
||||
requires kIsWritable;
|
||||
|
||||
/** Notify the view that the issuer self-debited `amount`. */
|
||||
void
|
||||
issuerSelfDebitHook(std::uint64_t amount)
|
||||
requires kIsWritable;
|
||||
|
||||
/** Lock MPT for escrow from `sender`. The amount must match this issuance. */
|
||||
[[nodiscard]] TER
|
||||
lockEscrow(AccountID const& sender, STAmount const& amount, beast::Journal j)
|
||||
requires kIsWritable;
|
||||
|
||||
/** Unlock previously-escrowed MPT, transferring `netAmount` to `receiver`,
|
||||
* with `grossAmount - netAmount` accounted as a transfer fee against
|
||||
* OutstandingAmount.
|
||||
*/
|
||||
[[nodiscard]] TER
|
||||
unlockEscrow(
|
||||
AccountID const& sender,
|
||||
AccountID const& receiver,
|
||||
STAmount const& netAmount,
|
||||
STAmount const& grossAmount,
|
||||
beast::Journal j)
|
||||
requires kIsWritable;
|
||||
|
||||
private:
|
||||
// Private constructor only used by `makeNew`.
|
||||
MPTokenIssuance(MPTID const& mptID, ApplyView& view, beast::Journal j, std::shared_ptr<SLE> sle)
|
||||
requires kIsWritable
|
||||
: SLEBase<ViewT>(std::move(sle), view, j), mptID_(mptID), mptIssue_(MPTIssue(mptID))
|
||||
{
|
||||
this->insert();
|
||||
}
|
||||
};
|
||||
|
||||
// CTAD deduction guides — bare MPTokenIssuance(view, ...) always deduces read-only.
|
||||
// For writable access, use WMPTokenIssuance(view, ...) explicitly.
|
||||
MPTokenIssuance(ReadView const&, MPTIssue const&) -> MPTokenIssuance<ReadView>;
|
||||
MPTokenIssuance(ReadView const&, MPTIssue const&, beast::Journal) -> MPTokenIssuance<ReadView>;
|
||||
MPTokenIssuance(ReadView const&, MPTID const&) -> MPTokenIssuance<ReadView>;
|
||||
MPTokenIssuance(ReadView const&, MPTID const&, beast::Journal) -> MPTokenIssuance<ReadView>;
|
||||
|
||||
// Backward-compatible aliases
|
||||
using RMPTokenIssuance = MPTokenIssuance<ReadView>;
|
||||
using WMPTokenIssuance = MPTokenIssuance<ApplyView>;
|
||||
|
||||
// Explicit instantiation declarations (definitions in .cpp)
|
||||
extern template class MPTokenIssuance<ReadView>;
|
||||
extern template class MPTokenIssuance<ApplyView>;
|
||||
|
||||
/** Check if Asset can be traded on DEX. return tecNO_PERMISSION
|
||||
* if it doesn't and tesSUCCESS otherwise.
|
||||
@@ -121,63 +301,6 @@ canTransfer(
|
||||
[[nodiscard]] TER
|
||||
canTrade(ReadView const& view, Asset const& asset);
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//
|
||||
// Empty holding operations (MPT-specific)
|
||||
//
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
[[nodiscard]] TER
|
||||
addEmptyHolding(
|
||||
ApplyView& view,
|
||||
AccountID const& accountID,
|
||||
XRPAmount priorBalance,
|
||||
MPTIssue const& mptIssue,
|
||||
beast::Journal journal);
|
||||
|
||||
[[nodiscard]] TER
|
||||
removeEmptyHolding(
|
||||
ApplyView& view,
|
||||
AccountID const& accountID,
|
||||
MPTIssue const& mptIssue,
|
||||
beast::Journal journal);
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//
|
||||
// Escrow operations (MPT-specific)
|
||||
//
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
TER
|
||||
lockEscrowMPT(
|
||||
ApplyView& view,
|
||||
AccountID const& uGrantorID,
|
||||
STAmount const& saAmount,
|
||||
beast::Journal j);
|
||||
|
||||
TER
|
||||
unlockEscrowMPT(
|
||||
ApplyView& view,
|
||||
AccountID const& uGrantorID,
|
||||
AccountID const& uGranteeID,
|
||||
STAmount const& netAmount,
|
||||
STAmount const& grossAmount,
|
||||
beast::Journal j);
|
||||
|
||||
TER
|
||||
createMPToken(
|
||||
ApplyView& view,
|
||||
MPTID const& mptIssuanceID,
|
||||
AccountID const& account,
|
||||
std::uint32_t const flags);
|
||||
|
||||
TER
|
||||
checkCreateMPT(
|
||||
xrpl::ApplyView& view,
|
||||
xrpl::MPTIssue const& mptIssue,
|
||||
xrpl::AccountID const& holder,
|
||||
beast::Journal j);
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//
|
||||
// MPT Overflow related
|
||||
@@ -193,9 +316,6 @@ maxMPTAmount(SLE const& sleIssuance);
|
||||
std::int64_t
|
||||
availableMPTAmount(SLE const& sleIssuance);
|
||||
|
||||
std::int64_t
|
||||
availableMPTAmount(ReadView const& view, MPTID const& mptID);
|
||||
|
||||
/** Checks for two types of OutstandingAmount overflow during a send operation.
|
||||
* 1. **Direct directSendNoFee (Overflow: No):** A true overflow check when
|
||||
* `OutstandingAmount > MaximumAmount`. This threshold is used for direct
|
||||
@@ -211,21 +331,15 @@ isMPTOverflow(
|
||||
std::int64_t maximumAmount,
|
||||
AllowMPTOverflow allowOverflow);
|
||||
|
||||
/**
|
||||
* Determine funds available for an issuer to sell in an issuer owned offer.
|
||||
* Issuing step, which could be either MPTEndPointStep last step or BookStep's
|
||||
* TakerPays may overflow OutstandingAmount. Redeeming step, in BookStep's
|
||||
* TakerGets redeems the offer's owner funds, essentially balancing out
|
||||
* the overflow, unless the offer's owner is the issuer.
|
||||
/** Delete AMMs MPToken. The passed `sle` must be obtained from a prior
|
||||
* call to view.peek().
|
||||
*/
|
||||
[[nodiscard]] STAmount
|
||||
issuerFundsToSelfIssue(ReadView const& view, MPTIssue const& issue);
|
||||
|
||||
/** Facilitate tracking of MPT sold by an issuer owning MPT sell offer.
|
||||
* See ApplyView::issuerSelfDebitHookMPT().
|
||||
*/
|
||||
void
|
||||
issuerSelfDebitHookMPT(ApplyView& view, MPTIssue const& issue, std::uint64_t amount);
|
||||
[[nodiscard]] TER
|
||||
deleteAMMMPToken(
|
||||
ApplyView& view,
|
||||
std::shared_ptr<SLE> sleMPT,
|
||||
AccountID const& ammAccountID,
|
||||
beast::Journal j);
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//
|
||||
|
||||
53
include/xrpl/ledger/helpers/README.md
Normal file
53
include/xrpl/ledger/helpers/README.md
Normal file
@@ -0,0 +1,53 @@
|
||||
# Ledger Entry Helpers (`helpers/`)
|
||||
|
||||
## Overview
|
||||
|
||||
This folder contains helper classes and free functions for working with **Serialized Ledger Entries (SLEs)**. Its centerpiece is `SLEBase.h`, which defines the template class `SLEBase<ViewT>` — a type-safe, context-aware wrapper around the raw `std::shared_ptr<SLE>` used throughout the rest of the codebase.
|
||||
|
||||
## The Problem: Untyped SLE Access
|
||||
|
||||
Historically, ledger entries are passed around as bare `std::shared_ptr<SLE>` (or `std::shared_ptr<SLE const>`). This has several drawbacks:
|
||||
|
||||
1. **No compile-time entry-type safety.** Any code holding an `std::shared_ptr<SLE>` can read or write _any_ field on _any_ ledger entry type. Nothing prevents you from calling `sle->getFieldU32(sfOwnerCount)` on an Offer SLE, even though Offers don't have that field.
|
||||
|
||||
2. **No read/write distinction.** A function that only needs to _read_ an entry still receives a mutable `std::shared_ptr<SLE>`, making it easy to accidentally mutate state. Conversely, a function that _must_ write has no way to express that requirement in its signature.
|
||||
|
||||
3. **No association with the view.** The SLE and the `ReadView` / `ApplyView` it came from travel as separate arguments, so callers must manually keep them in sync and remember to call `view.update(sle)` after mutations.
|
||||
|
||||
## The Solution: `SLEBase.h`
|
||||
|
||||
`SLEBase.h` introduces a single template class `SLEBase<ViewT>` that pairs an SLE with its view context and enforces read/write semantics at compile time via `requires` clauses.
|
||||
|
||||
**`SLEBase<ReadView>`** holds a `std::shared_ptr<SLE const>` and a `ReadView const&`. Write-only members are excluded at compile time.
|
||||
holds a mutable `std::shared_ptr<SLE>`, an `ApplyView&`, and a `Keylet`. It exposes `insert()`, `update()`, `erase()`, and `newSLE()` to keep the SLE and its view in sync automatically.
|
||||
|
||||
A converting constructor allows implicit conversion from `SLEBase<ApplyView>` to `SLEBase<ReadView>`, so functions taking a read-only wrapper can accept a writable one without a cast.
|
||||
|
||||
### Template Pattern
|
||||
|
||||
Each entry type is a single template class parameterized on the view type:
|
||||
|
||||
```
|
||||
AccountRoot<ReadView> — read-only: RAccountRoot
|
||||
AccountRoot<ApplyView> — writable: WAccountRoot
|
||||
```
|
||||
|
||||
Both specializations share all domain read methods. Write methods on `WAccountRoot` are gated with `requires is_writable` so they are unavailable on `RAccountRoot` at compile time. The `R`/`W` prefix aliases (`RAccountRoot`, `WAccountRoot`) are provided for convenience and backward compatibility.
|
||||
|
||||
## Files in This Directory
|
||||
|
||||
| File | Description |
|
||||
| ---------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| `SLEBase.h` | Template base class `SLEBase<ViewT>` for read-only and writable SLE wrappers |
|
||||
| `AccountRootHelpers.h` | `AccountRoot<ViewT>` wrapper (`RAccountRoot`, `WAccountRoot`) and free functions for pseudo-accounts |
|
||||
| `CredentialHelpers.h` | Free functions for Credential ledger entries |
|
||||
| `DirectoryHelpers.h` | Free functions for directory traversal (`dirFirst`, `dirNext`, `forEachItem`, etc.) |
|
||||
| `MPTokenHelpers.h` | Free functions for MPToken ledger entries and MPTokenIssuance<ViewT> wrapper (`RMPTokenIssuance`, `WMPTokenIssuance`) functions for MPTokenIssuance objects |
|
||||
| `OfferHelpers.h` | Free function `offerDelete` for removing Offer entries |
|
||||
| `RippleStateHelpers.h` | Free functions for RippleState (trust line) entries: credit, freeze, issuance, authorization |
|
||||
| `TokenHelpers.h` | Shared token helpers (freeze/auth checks used by both IOU and MPT paths) |
|
||||
| `VaultHelpers.h` | Free functions for Vault ledger entries |
|
||||
|
||||
## Migration Status
|
||||
|
||||
This migration is still in progress. New code should prefer the wrapper style where possible; existing free functions will be migrated incrementally.
|
||||
@@ -3,12 +3,14 @@
|
||||
#include <xrpl/beast/utility/Journal.h>
|
||||
#include <xrpl/ledger/ApplyView.h>
|
||||
#include <xrpl/ledger/ReadView.h>
|
||||
#include <xrpl/ledger/helpers/AccountRootHelpers.h>
|
||||
#include <xrpl/ledger/helpers/TokenHelpers.h>
|
||||
#include <xrpl/protocol/IOUAmount.h>
|
||||
#include <xrpl/protocol/Issue.h>
|
||||
#include <xrpl/protocol/STAmount.h>
|
||||
#include <xrpl/protocol/STLedgerEntry.h>
|
||||
#include <xrpl/protocol/TER.h>
|
||||
#include <xrpl/protocol/UintTypes.h>
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//
|
||||
@@ -20,137 +22,218 @@ namespace xrpl {
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//
|
||||
// Credit functions (from Credit.h)
|
||||
// IOUIssuance ledger entry wrapper (view-parameterized)
|
||||
//
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/** Calculate the maximum amount of IOUs that an account can hold
|
||||
@param view the ledger to check against.
|
||||
@param account the account of interest.
|
||||
@param issuer the issuer of the IOU.
|
||||
@param currency the IOU to check.
|
||||
@return The maximum amount that can be held.
|
||||
*/
|
||||
/** @{ */
|
||||
STAmount
|
||||
creditLimit(
|
||||
ReadView const& view,
|
||||
AccountID const& account,
|
||||
AccountID const& issuer,
|
||||
Currency const& currency);
|
||||
/**
|
||||
* View-parameterized wrapper for an IOU issuance.
|
||||
*
|
||||
* Because IOUs have no dedicated ledger entry — issuance properties live on
|
||||
* the issuer's AccountRoot — IOUIssuance<V> inherits from AccountRoot<V> and
|
||||
* adds the currency context plus IOU-specific accessors (RequireAuth /
|
||||
* AllowTrustLineClawback flags, freeze checks against the holder's trust
|
||||
* line, etc.).
|
||||
*
|
||||
* IOUIssuance<ReadView> — read-only
|
||||
* IOUIssuance<ApplyView> — read-write
|
||||
*/
|
||||
template <typename ViewT>
|
||||
class IOUIssuance : public AccountRoot<ViewT>, public TokenBase<ViewT>
|
||||
{
|
||||
static constexpr bool kIsWritable = SLEBase<ViewT>::kIsWritable;
|
||||
|
||||
IOUAmount
|
||||
creditLimit2(ReadView const& v, AccountID const& acc, AccountID const& iss, Currency const& cur);
|
||||
/** @} */
|
||||
Currency const currency_;
|
||||
|
||||
/** Returns the amount of IOUs issued by issuer that are held by an account
|
||||
@param view the ledger to check against.
|
||||
@param account the account of interest.
|
||||
@param issuer the issuer of the IOU.
|
||||
@param currency the IOU to check.
|
||||
*/
|
||||
/** @{ */
|
||||
STAmount
|
||||
creditBalance(
|
||||
ReadView const& view,
|
||||
AccountID const& account,
|
||||
AccountID const& issuer,
|
||||
Currency const& currency);
|
||||
/** @} */
|
||||
public:
|
||||
/** Constructor for read-only context (Issue). */
|
||||
IOUIssuance(
|
||||
ReadView const& view,
|
||||
Issue const& issue,
|
||||
beast::Journal j = beast::Journal{beast::Journal::getNullSink()})
|
||||
requires(!kIsWritable)
|
||||
: AccountRoot<ViewT>(issue.getIssuer(), view, j), currency_(issue.currency)
|
||||
{
|
||||
}
|
||||
|
||||
/** Constructor for read-only context (issuer + currency). */
|
||||
IOUIssuance(
|
||||
ReadView const& view,
|
||||
AccountID const& issuer,
|
||||
Currency const& currency,
|
||||
beast::Journal j = beast::Journal{beast::Journal::getNullSink()})
|
||||
requires(!kIsWritable)
|
||||
: AccountRoot<ViewT>(issuer, view, j), currency_(currency)
|
||||
{
|
||||
}
|
||||
|
||||
/** Constructor for writable context (Issue). */
|
||||
IOUIssuance(
|
||||
ApplyView& view,
|
||||
Issue const& issue,
|
||||
beast::Journal j = beast::Journal{beast::Journal::getNullSink()})
|
||||
requires kIsWritable
|
||||
: AccountRoot<ViewT>(issue.getIssuer(), view, j), currency_(issue.currency)
|
||||
{
|
||||
}
|
||||
|
||||
/** Constructor for writable context (issuer + currency). */
|
||||
IOUIssuance(
|
||||
ApplyView& view,
|
||||
AccountID const& issuer,
|
||||
Currency const& currency,
|
||||
beast::Journal j = beast::Journal{beast::Journal::getNullSink()})
|
||||
requires kIsWritable
|
||||
: AccountRoot<ViewT>(issuer, view, j), currency_(currency)
|
||||
{
|
||||
}
|
||||
|
||||
/** Converting constructor: writable → read-only. */
|
||||
template <WritableView OtherViewT>
|
||||
IOUIssuance(IOUIssuance<OtherViewT> const& other)
|
||||
requires(!kIsWritable)
|
||||
: AccountRoot<ViewT>(other), currency_(other.getCurrency())
|
||||
{
|
||||
}
|
||||
|
||||
[[nodiscard]] Currency const&
|
||||
getCurrency() const
|
||||
{
|
||||
return currency_;
|
||||
}
|
||||
|
||||
[[nodiscard]] Issue
|
||||
getIssue() const
|
||||
{
|
||||
return Issue{currency_, this->id()};
|
||||
}
|
||||
|
||||
// --- IOU-specific domain methods ---
|
||||
|
||||
/** Returns IOU issuer transfer fee as Rate (delegates to AccountRoot). */
|
||||
[[nodiscard]] Rate
|
||||
transferRate() const override
|
||||
{
|
||||
return AccountRoot<ViewT>::transferRate();
|
||||
}
|
||||
|
||||
/** Check if the issuer is globally frozen (delegates to AccountRoot). */
|
||||
[[nodiscard]] bool
|
||||
isGlobalFrozen() const override
|
||||
{
|
||||
return AccountRoot<ViewT>::isGlobalFrozen();
|
||||
}
|
||||
|
||||
/** Check if the issuer requires holder authorization (lsfRequireAuth). */
|
||||
[[nodiscard]] bool
|
||||
requiresAuth() const override;
|
||||
|
||||
/** Check if the issuer has enabled clawback (lsfAllowTrustLineClawback). */
|
||||
[[nodiscard]] bool
|
||||
canClawback() const override;
|
||||
|
||||
/** True if the trust line between `account` and the issuer has the
|
||||
* issuer-side freeze flag set.
|
||||
*/
|
||||
[[nodiscard]] bool
|
||||
isIndividualFrozen(AccountID const& account) const override;
|
||||
|
||||
/** True if the issuance is globally frozen or the trust line is frozen.
|
||||
* `depth` is ignored for IOUs (no vault recursion). */
|
||||
[[nodiscard]] bool
|
||||
isFrozen(AccountID const& account, int depth = 0) const override;
|
||||
|
||||
/** True if the trust line has the issuer-side deep-freeze flag set. */
|
||||
[[nodiscard]] bool
|
||||
isDeepFrozen(AccountID const& account) const;
|
||||
|
||||
/** Check if `account` is allowed to hold this IOU.
|
||||
* `depth` is ignored for IOUs (no vault recursion). */
|
||||
[[nodiscard]] TER
|
||||
requireAuth(AccountID const& account, AuthType authType = AuthType::Legacy, int depth = 0)
|
||||
const override;
|
||||
|
||||
/** Check if `from` is allowed to send this IOU to `to`. */
|
||||
[[nodiscard]] TER
|
||||
canTransfer(AccountID const& from, AccountID const& to) const override;
|
||||
|
||||
// --- Credit / balance ---
|
||||
|
||||
/** Maximum amount of this IOU that `account` can hold. */
|
||||
[[nodiscard]] STAmount
|
||||
creditLimit(AccountID const& account) const;
|
||||
|
||||
[[nodiscard]] IOUAmount
|
||||
creditLimit2(AccountID const& account) const;
|
||||
|
||||
/** Amount of this IOU held by `account`. */
|
||||
[[nodiscard]] STAmount
|
||||
creditBalance(AccountID const& account) const;
|
||||
|
||||
// --- Trust line operations (writable) ---
|
||||
|
||||
/** Create a trust line for this IOU's currency. */
|
||||
[[nodiscard]] TER
|
||||
trustCreate(
|
||||
bool const bSrcHigh,
|
||||
AccountID const& uSrcAccountID,
|
||||
AccountID const& uDstAccountID,
|
||||
uint256 const& uIndex,
|
||||
WAccountRoot& wrappedAcct,
|
||||
bool const bAuth,
|
||||
bool const bNoRipple,
|
||||
bool const bFreeze,
|
||||
bool bDeepFreeze,
|
||||
STAmount const& saBalance,
|
||||
STAmount const& saLimit,
|
||||
std::uint32_t uQualityIn,
|
||||
std::uint32_t uQualityOut,
|
||||
beast::Journal j)
|
||||
requires kIsWritable;
|
||||
|
||||
/** Add an empty trust line for `accountID`. */
|
||||
[[nodiscard]] TER
|
||||
addEmptyHolding(AccountID const& accountID, XRPAmount priorBalance, beast::Journal journal)
|
||||
requires kIsWritable;
|
||||
|
||||
/** Remove an empty trust line for `accountID`. */
|
||||
[[nodiscard]] TER
|
||||
removeEmptyHolding(AccountID const& accountID, beast::Journal journal)
|
||||
requires kIsWritable;
|
||||
|
||||
/** Issue `amount` of this IOU from the issuer to `account`. */
|
||||
[[nodiscard]] TER
|
||||
issue(AccountID const& account, STAmount const& amount, beast::Journal j)
|
||||
requires kIsWritable;
|
||||
|
||||
/** Redeem `amount` of this IOU from `account` back to the issuer. */
|
||||
[[nodiscard]] TER
|
||||
redeem(AccountID const& account, STAmount const& amount, beast::Journal j)
|
||||
requires kIsWritable;
|
||||
};
|
||||
|
||||
// CTAD deduction guides — bare IOUIssuance(view, ...) always deduces read-only.
|
||||
// For writable access, use WIOUIssuance(view, ...) explicitly.
|
||||
IOUIssuance(ReadView const&, Issue const&) -> IOUIssuance<ReadView>;
|
||||
IOUIssuance(ReadView const&, Issue const&, beast::Journal) -> IOUIssuance<ReadView>;
|
||||
IOUIssuance(ReadView const&, AccountID const&, Currency const&) -> IOUIssuance<ReadView>;
|
||||
IOUIssuance(ReadView const&, AccountID const&, Currency const&, beast::Journal)
|
||||
-> IOUIssuance<ReadView>;
|
||||
|
||||
// Backward-compatible aliases
|
||||
using RIOUIssuance = IOUIssuance<ReadView>;
|
||||
using WIOUIssuance = IOUIssuance<ApplyView>;
|
||||
|
||||
// Explicit instantiation declarations (definitions in .cpp)
|
||||
extern template class IOUIssuance<ReadView>;
|
||||
extern template class IOUIssuance<ApplyView>;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//
|
||||
// Freeze checking (IOU-specific)
|
||||
// Trust line operations (SLE-level, no issuance context)
|
||||
//
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
[[nodiscard]] bool
|
||||
isIndividualFrozen(
|
||||
ReadView const& view,
|
||||
AccountID const& account,
|
||||
Currency const& currency,
|
||||
AccountID const& issuer);
|
||||
|
||||
[[nodiscard]] inline bool
|
||||
isIndividualFrozen(ReadView const& view, AccountID const& account, Issue const& issue)
|
||||
{
|
||||
return isIndividualFrozen(view, account, issue.currency, issue.account);
|
||||
}
|
||||
|
||||
[[nodiscard]] bool
|
||||
isFrozen(
|
||||
ReadView const& view,
|
||||
AccountID const& account,
|
||||
Currency const& currency,
|
||||
AccountID const& issuer);
|
||||
|
||||
[[nodiscard]] inline bool
|
||||
isFrozen(ReadView const& view, AccountID const& account, Issue const& issue)
|
||||
{
|
||||
return isFrozen(view, account, issue.currency, issue.account);
|
||||
}
|
||||
|
||||
// Overload with depth parameter for uniformity with MPTIssue version.
|
||||
// The depth parameter is ignored for IOUs since they don't have vault recursion.
|
||||
[[nodiscard]] inline bool
|
||||
isFrozen(ReadView const& view, AccountID const& account, Issue const& issue, int /*depth*/)
|
||||
{
|
||||
return isFrozen(view, account, issue);
|
||||
}
|
||||
|
||||
[[nodiscard]] bool
|
||||
isDeepFrozen(
|
||||
ReadView const& view,
|
||||
AccountID const& account,
|
||||
Currency const& currency,
|
||||
AccountID const& issuer);
|
||||
|
||||
[[nodiscard]] inline bool
|
||||
isDeepFrozen(
|
||||
ReadView const& view,
|
||||
AccountID const& account,
|
||||
Issue const& issue,
|
||||
int = 0 /*ignored*/)
|
||||
{
|
||||
return isDeepFrozen(view, account, issue.currency, issue.account);
|
||||
}
|
||||
|
||||
[[nodiscard]] inline TER
|
||||
checkDeepFrozen(ReadView const& view, AccountID const& account, Issue const& issue)
|
||||
{
|
||||
return isDeepFrozen(view, account, issue) ? (TER)tecFROZEN : (TER)tesSUCCESS;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//
|
||||
// Trust line operations
|
||||
//
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/** Create a trust line
|
||||
|
||||
This can set an initial balance.
|
||||
*/
|
||||
[[nodiscard]] TER
|
||||
trustCreate(
|
||||
ApplyView& view,
|
||||
bool const bSrcHigh,
|
||||
AccountID const& uSrcAccountID,
|
||||
AccountID const& uDstAccountID,
|
||||
uint256 const& uIndex, // --> ripple state entry
|
||||
SLE::ref sleAccount, // --> the account being set.
|
||||
bool const bAuth, // --> authorize account.
|
||||
bool const bNoRipple, // --> others cannot ripple through
|
||||
bool const bFreeze, // --> funds cannot leave
|
||||
bool bDeepFreeze, // --> can neither receive nor send funds
|
||||
STAmount const& saBalance, // --> balance of account being set.
|
||||
// Issuer should be noAccount()
|
||||
STAmount const& saLimit, // --> limit for account being set.
|
||||
// Issuer should be the account being set.
|
||||
std::uint32_t uQualityIn,
|
||||
std::uint32_t uQualityOut,
|
||||
beast::Journal j);
|
||||
|
||||
[[nodiscard]] TER
|
||||
trustDelete(
|
||||
ApplyView& view,
|
||||
@@ -159,88 +242,6 @@ trustDelete(
|
||||
AccountID const& uHighAccountID,
|
||||
beast::Journal j);
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//
|
||||
// IOU issuance/redemption
|
||||
//
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
[[nodiscard]] TER
|
||||
issueIOU(
|
||||
ApplyView& view,
|
||||
AccountID const& account,
|
||||
STAmount const& amount,
|
||||
Issue const& issue,
|
||||
beast::Journal j);
|
||||
|
||||
[[nodiscard]] TER
|
||||
redeemIOU(
|
||||
ApplyView& view,
|
||||
AccountID const& account,
|
||||
STAmount const& amount,
|
||||
Issue const& issue,
|
||||
beast::Journal j);
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//
|
||||
// Authorization and transfer checks (IOU-specific)
|
||||
//
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/** Check if the account lacks required authorization.
|
||||
*
|
||||
* Return tecNO_AUTH or tecNO_LINE if it does
|
||||
* and tesSUCCESS otherwise.
|
||||
*
|
||||
* If StrongAuth then return tecNO_LINE if the RippleState doesn't exist. Return
|
||||
* tecNO_AUTH if lsfRequireAuth is set on the issuer's AccountRoot, and the
|
||||
* RippleState does exist, and the RippleState is not authorized.
|
||||
*
|
||||
* If WeakAuth then return tecNO_AUTH if lsfRequireAuth is set, and the
|
||||
* RippleState exists, and is not authorized. Return tecNO_LINE if
|
||||
* lsfRequireAuth is set and the RippleState doesn't exist. Consequently, if
|
||||
* WeakAuth and lsfRequireAuth is *not* set, this function will return
|
||||
* tesSUCCESS even if RippleState does *not* exist.
|
||||
*
|
||||
* The default "Legacy" auth type is equivalent to WeakAuth.
|
||||
*/
|
||||
[[nodiscard]] TER
|
||||
requireAuth(
|
||||
ReadView const& view,
|
||||
Issue const& issue,
|
||||
AccountID const& account,
|
||||
AuthType authType = AuthType::Legacy);
|
||||
|
||||
/** Check if the destination account is allowed
|
||||
* to receive IOU. Return terNO_RIPPLE if rippling is
|
||||
* disabled on both sides and tesSUCCESS otherwise.
|
||||
*/
|
||||
[[nodiscard]] TER
|
||||
canTransfer(ReadView const& view, Issue const& issue, AccountID const& from, AccountID const& to);
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//
|
||||
// Empty holding operations (IOU-specific)
|
||||
//
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/// Any transactors that call addEmptyHolding() in doApply must call
|
||||
/// canAddHolding() in preflight with the same View and Asset
|
||||
[[nodiscard]] TER
|
||||
addEmptyHolding(
|
||||
ApplyView& view,
|
||||
AccountID const& accountID,
|
||||
XRPAmount priorBalance,
|
||||
Issue const& issue,
|
||||
beast::Journal journal);
|
||||
|
||||
[[nodiscard]] TER
|
||||
removeEmptyHolding(
|
||||
ApplyView& view,
|
||||
AccountID const& accountID,
|
||||
Issue const& issue,
|
||||
beast::Journal journal);
|
||||
|
||||
/** Delete trustline to AMM. The passed `sle` must be obtained from a prior
|
||||
* call to view.peek(). Fail if neither side of the trustline is AMM or
|
||||
* if ammAccountID is seated and is not one of the trustline's side.
|
||||
@@ -252,14 +253,4 @@ deleteAMMTrustLine(
|
||||
std::optional<AccountID> const& ammAccountID,
|
||||
beast::Journal j);
|
||||
|
||||
/** Delete AMMs MPToken. The passed `sle` must be obtained from a prior
|
||||
* call to view.peek().
|
||||
*/
|
||||
[[nodiscard]] TER
|
||||
deleteAMMMPToken(
|
||||
ApplyView& view,
|
||||
std::shared_ptr<SLE> sleMPT,
|
||||
AccountID const& ammAccountID,
|
||||
beast::Journal j);
|
||||
|
||||
} // namespace xrpl
|
||||
|
||||
240
include/xrpl/ledger/helpers/SLEBase.h
Normal file
240
include/xrpl/ledger/helpers/SLEBase.h
Normal file
@@ -0,0 +1,240 @@
|
||||
#pragma once
|
||||
|
||||
#include <xrpl/beast/utility/instrumentation.h>
|
||||
#include <xrpl/ledger/ApplyView.h>
|
||||
#include <xrpl/ledger/ReadView.h>
|
||||
#include <xrpl/protocol/STLedgerEntry.h>
|
||||
|
||||
#include <concepts>
|
||||
#include <memory>
|
||||
#include <stdexcept>
|
||||
#include <type_traits>
|
||||
|
||||
namespace xrpl {
|
||||
|
||||
// Concept to distinguish read-only vs writable view types
|
||||
template <typename V>
|
||||
concept WritableView = std::derived_from<V, ApplyView>;
|
||||
|
||||
/**
|
||||
* View-parameterized base class for all ledger entry wrappers.
|
||||
*
|
||||
* SLEBase<ReadView> — read-only: holds shared_ptr<SLE const> + ReadView const&
|
||||
* SLEBase<ApplyView> — writable: holds shared_ptr<SLE> + ApplyView& + Keylet,
|
||||
* plus insert/update/erase operations
|
||||
*
|
||||
* Write-only members are gated by `requires` clauses, providing compile-time
|
||||
* guarantees that read-only wrappers cannot mutate state.
|
||||
*
|
||||
* Derived classes should provide domain-specific accessors that hide
|
||||
* implementation details of the underlying ledger entry format.
|
||||
*/
|
||||
template <typename ViewT>
|
||||
class SLEBase
|
||||
{
|
||||
public:
|
||||
static constexpr bool kIsWritable = WritableView<ViewT>;
|
||||
|
||||
// SLE pointer type: mutable for writable views, const for read-only
|
||||
using sle_ptr_type = std::conditional_t<kIsWritable, std::shared_ptr<SLE>, SLE::const_pointer>;
|
||||
|
||||
// View reference type: ApplyView& for writable, ReadView const& for read-only
|
||||
using view_ref_type = std::conditional_t<kIsWritable, ApplyView&, ReadView const&>;
|
||||
|
||||
virtual ~SLEBase() = default;
|
||||
|
||||
SLEBase(SLEBase const&) = default;
|
||||
SLEBase(SLEBase&&) = default;
|
||||
SLEBase&
|
||||
operator=(SLEBase const&) = delete;
|
||||
SLEBase&
|
||||
operator=(SLEBase&&) = delete;
|
||||
SLEBase() = delete;
|
||||
|
||||
// --- Common interface (always available) ---
|
||||
|
||||
/** Returns true if the ledger entry exists */
|
||||
[[nodiscard]] bool
|
||||
exists() const
|
||||
{
|
||||
return sle_ != nullptr;
|
||||
}
|
||||
|
||||
/** Explicit conversion to bool for convenient existence checking */
|
||||
explicit
|
||||
operator bool() const
|
||||
{
|
||||
return exists();
|
||||
}
|
||||
|
||||
/** Returns the underlying SLE for read access */
|
||||
[[nodiscard]] SLE::const_pointer
|
||||
sle() const
|
||||
{
|
||||
return sle_;
|
||||
}
|
||||
|
||||
/** Returns the read view (always available; ApplyView inherits ReadView) */
|
||||
[[nodiscard]] ReadView const&
|
||||
readView() const
|
||||
{
|
||||
return view_;
|
||||
}
|
||||
|
||||
/** Const dereference operators (always available) */
|
||||
STLedgerEntry const*
|
||||
operator->() const
|
||||
{
|
||||
XRPL_ASSERT(exists(), "xrpl::SLEBase::operator-> : exists");
|
||||
return sle_.get();
|
||||
}
|
||||
|
||||
STLedgerEntry const&
|
||||
operator*() const
|
||||
{
|
||||
XRPL_ASSERT(exists(), "xrpl::SLEBase::operator* : exists");
|
||||
return *sle_;
|
||||
}
|
||||
|
||||
// --- Writable interface (compile-time gated) ---
|
||||
|
||||
/** Returns a mutable SLE for write operations */
|
||||
[[nodiscard]] sle_ptr_type const&
|
||||
mutableSle() const
|
||||
requires kIsWritable
|
||||
{
|
||||
return sle_;
|
||||
}
|
||||
|
||||
/** Returns true if this wrapper supports write operations */
|
||||
[[nodiscard]] bool
|
||||
canModify() const
|
||||
requires kIsWritable
|
||||
{
|
||||
return sle_ != nullptr;
|
||||
}
|
||||
|
||||
/** Returns the apply view for write operations */
|
||||
[[nodiscard]] ApplyView&
|
||||
applyView() const
|
||||
requires kIsWritable
|
||||
{
|
||||
return view_;
|
||||
}
|
||||
|
||||
/** Mutable dereference operators */
|
||||
STLedgerEntry*
|
||||
operator->()
|
||||
requires kIsWritable
|
||||
{
|
||||
XRPL_ASSERT(canModify(), "xrpl::SLEBase::operator-> : can modify");
|
||||
return sle_.get();
|
||||
}
|
||||
|
||||
STLedgerEntry&
|
||||
operator*()
|
||||
requires kIsWritable
|
||||
{
|
||||
XRPL_ASSERT(canModify(), "xrpl::SLEBase::operator* : can modify");
|
||||
return *sle_;
|
||||
}
|
||||
|
||||
void
|
||||
insert()
|
||||
requires kIsWritable
|
||||
{
|
||||
XRPL_ASSERT(canModify(), "xrpl::SLEBase::insert : can modify");
|
||||
view_.insert(sle_);
|
||||
}
|
||||
|
||||
void
|
||||
erase()
|
||||
requires kIsWritable
|
||||
{
|
||||
XRPL_ASSERT(canModify(), "xrpl::SLEBase::erase : can modify");
|
||||
view_.erase(sle_);
|
||||
}
|
||||
|
||||
void
|
||||
update()
|
||||
requires kIsWritable
|
||||
{
|
||||
XRPL_ASSERT(canModify(), "xrpl::SLEBase::update : can modify");
|
||||
view_.update(sle_);
|
||||
}
|
||||
|
||||
void
|
||||
newSLE()
|
||||
requires kIsWritable
|
||||
{
|
||||
XRPL_ASSERT(!canModify(), "xrpl::SLEBase::newSLE : no existing SLE");
|
||||
sle_ = std::make_shared<SLE>(key_);
|
||||
}
|
||||
|
||||
[[nodiscard]] beast::Journal
|
||||
journal() const
|
||||
{
|
||||
return j_;
|
||||
}
|
||||
|
||||
protected:
|
||||
/** Constructor for read-only context */
|
||||
explicit SLEBase(
|
||||
SLE::const_pointer sle,
|
||||
ReadView const& view,
|
||||
beast::Journal j = beast::Journal{beast::Journal::getNullSink()})
|
||||
requires(!kIsWritable)
|
||||
: view_(view), sle_(std::move(sle)), j_(j)
|
||||
{
|
||||
}
|
||||
|
||||
/** Converting constructor: writable → read-only.
|
||||
* Enables implicit conversion from SLEBase<ApplyView> to
|
||||
* SLEBase<ReadView>, so functions taking ReadOnlySLE const& can
|
||||
* accept WritableSLE.
|
||||
*/
|
||||
template <WritableView OtherViewT>
|
||||
SLEBase(SLEBase<OtherViewT> const& other)
|
||||
requires(!kIsWritable)
|
||||
: view_(other.readView()), sle_(other.sle()), j_(other.journal())
|
||||
{
|
||||
}
|
||||
|
||||
/** Constructor for writable context (from existing SLE) */
|
||||
explicit SLEBase(
|
||||
std::shared_ptr<SLE> sle,
|
||||
ApplyView& view,
|
||||
beast::Journal j = beast::Journal{beast::Journal::getNullSink()})
|
||||
requires kIsWritable
|
||||
: view_(view)
|
||||
, key_(sle ? Keylet(sle->getType(), sle->key()) : Keylet(ltANY, uint256{}))
|
||||
, sle_(std::move(sle))
|
||||
, j_(j)
|
||||
{
|
||||
}
|
||||
|
||||
/** Constructor for writable context (peek from view by keylet) */
|
||||
explicit SLEBase(
|
||||
Keylet const& key,
|
||||
ApplyView& view,
|
||||
beast::Journal j = beast::Journal{beast::Journal::getNullSink()})
|
||||
requires kIsWritable
|
||||
: view_(view), key_(key), sle_(view_.peek(key)), j_(j)
|
||||
{
|
||||
}
|
||||
|
||||
view_ref_type view_;
|
||||
|
||||
// Keylet is only meaningful for writable views, but we conditionally
|
||||
// include it to avoid wasting space in read-only wrappers.
|
||||
struct Empty
|
||||
{
|
||||
};
|
||||
[[no_unique_address]]
|
||||
std::conditional_t<kIsWritable, Keylet, Empty> key_{};
|
||||
|
||||
sle_ptr_type sle_;
|
||||
beast::Journal j_;
|
||||
};
|
||||
|
||||
} // namespace xrpl
|
||||
@@ -45,6 +45,50 @@ enum class AllowMPTOverflow : bool { No = false, Yes };
|
||||
*/
|
||||
enum class AuthType { StrongAuth, WeakAuth, Legacy };
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//
|
||||
// TokenBase<ViewT>: abstract interface shared by MPTokenIssuance and IOUIssuance.
|
||||
//
|
||||
// This is a pure-interface base (no data members), used as a second base class
|
||||
// alongside SLEBase<V> (for MPT) or AccountRoot<V> (for IOU) so callers can hold
|
||||
// a polymorphic reference and dispatch without knowing the token kind. Methods
|
||||
// whose semantics differ slightly between IOU and MPT are unified here with the
|
||||
// MPT signature (e.g. `int depth`); IOU implementations ignore depth.
|
||||
//
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
template <typename ViewT>
|
||||
class TokenBase
|
||||
{
|
||||
public:
|
||||
virtual ~TokenBase() = default;
|
||||
|
||||
[[nodiscard]] virtual bool
|
||||
isGlobalFrozen() const = 0;
|
||||
|
||||
[[nodiscard]] virtual bool
|
||||
isIndividualFrozen(AccountID const& account) const = 0;
|
||||
|
||||
[[nodiscard]] virtual bool
|
||||
isFrozen(AccountID const& account, int depth = 0) const = 0;
|
||||
|
||||
[[nodiscard]] virtual Rate
|
||||
transferRate() const = 0;
|
||||
|
||||
[[nodiscard]] virtual TER
|
||||
requireAuth(AccountID const& account, AuthType authType = AuthType::Legacy, int depth = 0)
|
||||
const = 0;
|
||||
|
||||
[[nodiscard]] virtual TER
|
||||
canTransfer(AccountID const& from, AccountID const& to) const = 0;
|
||||
|
||||
[[nodiscard]] virtual bool
|
||||
canClawback() const = 0;
|
||||
|
||||
[[nodiscard]] virtual bool
|
||||
requiresAuth() const = 0;
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//
|
||||
// Freeze checking (Asset-based dispatchers)
|
||||
@@ -116,10 +160,10 @@ checkDeepFrozen(ReadView const& view, AccountID const& account, Asset const& ass
|
||||
|
||||
// Returns the amount an account can spend.
|
||||
//
|
||||
// If shSIMPLE_BALANCE is specified, this is the amount the account can spend
|
||||
// If SpendableHandling::SimpleBalance is specified, this is the amount the account can spend
|
||||
// without going into debt.
|
||||
//
|
||||
// If shFULL_BALANCE is specified, this is the amount the account can spend
|
||||
// If SpendableHandling::FullBalance is specified, this is the amount the account can spend
|
||||
// total. Specifically:
|
||||
// * The account can go into debt if using a trust line, and the other side has
|
||||
// a non-zero limit.
|
||||
@@ -245,7 +289,7 @@ canTransfer(ReadView const& view, Asset const& asset, AccountID const& from, Acc
|
||||
// Direct send w/o fees:
|
||||
// - Redeeming IOUs and/or sending sender's own IOUs.
|
||||
// - Create trust line of needed.
|
||||
// --> bCheckIssuer : normally require issuer to be involved.
|
||||
// bCheckIssuer : normally require issuer to be involved.
|
||||
// [[nodiscard]] // nodiscard commented out so DirectStep.cpp compiles.
|
||||
|
||||
/** Calls static directSendNoFeeIOU if saAmount represents Issue.
|
||||
|
||||
@@ -20,7 +20,7 @@ class HTTPClient
|
||||
public:
|
||||
explicit HTTPClient() = default;
|
||||
|
||||
static constexpr auto kMAX_CLIENT_HEADER_BYTES = kilobytes(32);
|
||||
static constexpr auto kMaxClientHeaderBytes = kilobytes(32);
|
||||
|
||||
static void
|
||||
initializeSSLContext(
|
||||
|
||||
@@ -29,7 +29,7 @@ enum class NodeObjectType : std::uint32_t {
|
||||
class NodeObject : public CountedObject<NodeObject>
|
||||
{
|
||||
public:
|
||||
static constexpr std::size_t kKEY_BYTES = 32;
|
||||
static constexpr std::size_t kKeyBytes = 32;
|
||||
|
||||
private:
|
||||
// This hack is used to make the constructor effectively private
|
||||
|
||||
@@ -9,13 +9,13 @@ namespace xrpl::NodeStore {
|
||||
// This is only used to pre-allocate the array for
|
||||
// batch objects and does not affect the amount written.
|
||||
//
|
||||
static constexpr auto kBATCH_WRITE_PREALLOCATION_SIZE = 256;
|
||||
static constexpr auto kBatchWritePreallocationSize = 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.
|
||||
//
|
||||
static constexpr auto kBATCH_WRITE_LIMIT_SIZE = 65536;
|
||||
static constexpr auto kBatchWriteLimitSize = 65536;
|
||||
|
||||
/** Return codes from Backend operations. */
|
||||
enum class Status {
|
||||
|
||||
@@ -55,7 +55,7 @@ lz4Compress(void const* in, std::size_t inSize, BufferFactory&& bf)
|
||||
using std::runtime_error;
|
||||
using namespace nudb::detail;
|
||||
std::pair<void const*, std::size_t> result;
|
||||
std::array<std::uint8_t, varint_traits<std::size_t>::kMAX> vi{};
|
||||
std::array<std::uint8_t, varint_traits<std::size_t>::kMax> vi{};
|
||||
auto const n = writeVarint(vi.data(), inSize);
|
||||
auto const outMax = LZ4_compressBound(inSize);
|
||||
std::uint8_t* out = reinterpret_cast<std::uint8_t*>(bf(n + outMax));
|
||||
@@ -254,12 +254,12 @@ nodeobjectCompress(void const* in, std::size_t inSize, BufferFactory&& bf)
|
||||
}
|
||||
}
|
||||
|
||||
std::array<std::uint8_t, varint_traits<std::size_t>::kMAX> vi{};
|
||||
std::array<std::uint8_t, varint_traits<std::size_t>::kMax> vi{};
|
||||
|
||||
constexpr std::size_t kCODEC_TYPE = 1;
|
||||
auto const vn = writeVarint(vi.data(), kCODEC_TYPE);
|
||||
static constexpr std::size_t kCodecType = 1;
|
||||
auto const vn = writeVarint(vi.data(), kCodecType);
|
||||
std::pair<void const*, std::size_t> result;
|
||||
switch (kCODEC_TYPE)
|
||||
switch (kCodecType)
|
||||
{
|
||||
// case 0 was uncompressed data; we always compress now.
|
||||
case 1: // lz4
|
||||
@@ -275,7 +275,7 @@ nodeobjectCompress(void const* in, std::size_t inSize, BufferFactory&& bf)
|
||||
break;
|
||||
}
|
||||
default:
|
||||
Throw<std::logic_error>("nodeobject codec: unknown=" + std::to_string(kCODEC_TYPE));
|
||||
Throw<std::logic_error>("nodeobject codec: unknown=" + std::to_string(kCodecType));
|
||||
};
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ struct varint_traits<T, true>
|
||||
{
|
||||
explicit varint_traits() = default;
|
||||
|
||||
static std::size_t constexpr kMAX = (8 * sizeof(T) + 6) / 7;
|
||||
static constexpr std::size_t kMax = (8 * sizeof(T) + 6) / 7;
|
||||
};
|
||||
|
||||
// Returns: Number of bytes consumed or 0 on error,
|
||||
|
||||
@@ -8,21 +8,21 @@
|
||||
|
||||
namespace xrpl {
|
||||
|
||||
std::uint16_t constexpr kTRADING_FEE_THRESHOLD = 1000; // 1%
|
||||
constexpr std::uint16_t kTradingFeeThreshold = 1000; // 1%
|
||||
|
||||
// Auction slot
|
||||
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;
|
||||
constexpr std::uint32_t kTotalTimeSlotSecs = 24 * 3600;
|
||||
constexpr std::uint16_t kAuctionSlotTimeIntervals = 20;
|
||||
constexpr std::uint16_t kAuctionSlotMaxAuthAccounts = 4;
|
||||
constexpr std::uint32_t kAuctionSlotFeeScaleFactor = 100000;
|
||||
constexpr std::uint32_t kAuctionSlotDiscountedFeeFraction = 10;
|
||||
constexpr std::uint32_t kAuctionSlotMinFeeFraction = 25;
|
||||
constexpr std::uint32_t kAuctionSlotIntervalDuration =
|
||||
kTotalTimeSlotSecs / kAuctionSlotTimeIntervals;
|
||||
|
||||
// Votes
|
||||
std::uint16_t constexpr kVOTE_MAX_SLOTS = 8;
|
||||
std::uint32_t constexpr kVOTE_WEIGHT_SCALE_FACTOR = 100000;
|
||||
constexpr std::uint16_t kVoteMaxSlots = 8;
|
||||
constexpr std::uint32_t kVoteWeightScaleFactor = 100000;
|
||||
|
||||
class STObject;
|
||||
class STAmount;
|
||||
@@ -77,7 +77,7 @@ ammEnabled(Rules const&);
|
||||
inline Number
|
||||
getFee(std::uint16_t tfee)
|
||||
{
|
||||
return Number{tfee} / kAUCTION_SLOT_FEE_SCALE_FACTOR;
|
||||
return Number{tfee} / kAuctionSlotFeeScaleFactor;
|
||||
}
|
||||
|
||||
/** Get fee multiplier (1 - tfee)
|
||||
|
||||
@@ -69,7 +69,7 @@ toIssuer(AccountID&, std::string const&);
|
||||
inline bool
|
||||
isXRP(AccountID const& c)
|
||||
{
|
||||
return c == beast::kZERO;
|
||||
return c == beast::kZero;
|
||||
}
|
||||
|
||||
// DEPRECATED
|
||||
|
||||
@@ -96,9 +96,9 @@ inline MPTAmount
|
||||
toAmount<MPTAmount>(STAmount const& amt)
|
||||
{
|
||||
XRPL_ASSERT(
|
||||
amt.holds<MPTIssue>() && amt.mantissa() <= kMAX_MP_TOKEN_AMOUNT && amt.exponent() == 0,
|
||||
amt.holds<MPTIssue>() && amt.mantissa() <= kMaxMpTokenAmount && amt.exponent() == 0,
|
||||
"xrpl::toAmount<MPTAmount> : maximum mantissa");
|
||||
if (amt.mantissa() > kMAX_MP_TOKEN_AMOUNT || amt.exponent() != 0)
|
||||
if (amt.mantissa() > kMaxMpTokenAmount || amt.exponent() != 0)
|
||||
Throw<std::runtime_error>("toAmount<MPTAmount>: invalid mantissa or exponent");
|
||||
bool const isNeg = amt.negative();
|
||||
std::int64_t const sMant = isNeg ? -std::int64_t(amt.mantissa()) : amt.mantissa();
|
||||
@@ -167,8 +167,8 @@ toAmount(Asset const& asset, Number const& n, Number::RoundingMode mode = Number
|
||||
}
|
||||
else
|
||||
{
|
||||
constexpr bool kALWAYS_FALSE = !std::is_same_v<T, T>;
|
||||
static_assert(kALWAYS_FALSE, "Unsupported type for toAmount");
|
||||
static constexpr bool kAlwaysFalse = !std::is_same_v<T, T>;
|
||||
static_assert(kAlwaysFalse, "Unsupported type for toAmount");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -178,30 +178,30 @@ toMaxAmount(Asset const& asset)
|
||||
{
|
||||
if constexpr (std::is_same_v<IOUAmount, T>)
|
||||
{
|
||||
return IOUAmount(STAmount::kMAX_VALUE, STAmount::kMAX_OFFSET);
|
||||
return IOUAmount(STAmount::kMaxValue, STAmount::kMaxOffset);
|
||||
}
|
||||
else if constexpr (std::is_same_v<XRPAmount, T>)
|
||||
{
|
||||
return XRPAmount(static_cast<std::int64_t>(STAmount::kMAX_NATIVE_N));
|
||||
return XRPAmount(static_cast<std::int64_t>(STAmount::kMaxNativeN));
|
||||
}
|
||||
else if constexpr (std::is_same_v<MPTAmount, T>)
|
||||
{
|
||||
return MPTAmount(kMAX_MP_TOKEN_AMOUNT);
|
||||
return MPTAmount(kMaxMpTokenAmount);
|
||||
}
|
||||
else if constexpr (std::is_same_v<STAmount, T>)
|
||||
{
|
||||
return asset.visit(
|
||||
[](Issue const& issue) {
|
||||
if (isXRP(issue))
|
||||
return STAmount(issue, static_cast<std::int64_t>(STAmount::kMAX_NATIVE_N));
|
||||
return STAmount(issue, STAmount::kMAX_VALUE, STAmount::kMAX_OFFSET);
|
||||
return STAmount(issue, static_cast<std::int64_t>(STAmount::kMaxNativeN));
|
||||
return STAmount(issue, STAmount::kMaxValue, STAmount::kMaxOffset);
|
||||
},
|
||||
[](MPTIssue const& issue) { return STAmount(issue, kMAX_MP_TOKEN_AMOUNT); });
|
||||
[](MPTIssue const& issue) { return STAmount(issue, kMaxMpTokenAmount); });
|
||||
}
|
||||
else
|
||||
{
|
||||
constexpr bool kALWAYS_FALSE = !std::is_same_v<T, T>;
|
||||
static_assert(kALWAYS_FALSE, "Unsupported type for toMaxAmount");
|
||||
static constexpr bool kAlwaysFalse = !std::is_same_v<T, T>;
|
||||
static_assert(kAlwaysFalse, "Unsupported type for toMaxAmount");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -233,8 +233,8 @@ getAsset(T const& amt)
|
||||
}
|
||||
else
|
||||
{
|
||||
constexpr bool kALWAYS_FALSE = !std::is_same_v<T, T>;
|
||||
static_assert(kALWAYS_FALSE, "Unsupported type for getIssue");
|
||||
static constexpr bool kAlwaysFalse = !std::is_same_v<T, T>;
|
||||
static_assert(kAlwaysFalse, "Unsupported type for getIssue");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -260,8 +260,8 @@ get(STAmount const& a)
|
||||
}
|
||||
else
|
||||
{
|
||||
constexpr bool kALWAYS_FALSE = !std::is_same_v<T, T>;
|
||||
static_assert(kALWAYS_FALSE, "Unsupported type for get");
|
||||
constexpr bool kAlwaysFalse = !std::is_same_v<T, T>;
|
||||
static_assert(kAlwaysFalse, "Unsupported type for get");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -35,49 +35,49 @@ namespace xrpl {
|
||||
namespace RPC {
|
||||
|
||||
template <unsigned int Version>
|
||||
constexpr static std::integral_constant<unsigned, Version> kAPI_VERSION = {};
|
||||
static constexpr std::integral_constant<unsigned, Version> kApiVersion = {};
|
||||
|
||||
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 constexpr auto kApiInvalidVersion = kApiVersion<0>;
|
||||
static constexpr auto kApiMinimumSupportedVersion = kApiVersion<1>;
|
||||
static constexpr auto kApiMaximumSupportedVersion = kApiVersion<2>;
|
||||
static constexpr auto kApiVersionIfUnspecified = kApiVersion<1>;
|
||||
static constexpr auto kApiCommandLineVersion = kApiVersion<1>; // TODO Bump to 2 later
|
||||
static constexpr auto kApiBetaVersion = kApiVersion<3>;
|
||||
static constexpr auto kApiMaximumValidVersion = kApiBetaVersion;
|
||||
|
||||
static_assert(kAPI_INVALID_VERSION < kAPI_MINIMUM_SUPPORTED_VERSION);
|
||||
static_assert(kApiInvalidVersion < kApiMinimumSupportedVersion);
|
||||
static_assert(
|
||||
kAPI_VERSION_IF_UNSPECIFIED >= kAPI_MINIMUM_SUPPORTED_VERSION &&
|
||||
kAPI_VERSION_IF_UNSPECIFIED <= kAPI_MAXIMUM_SUPPORTED_VERSION);
|
||||
kApiVersionIfUnspecified >= kApiMinimumSupportedVersion &&
|
||||
kApiVersionIfUnspecified <= kApiMaximumSupportedVersion);
|
||||
static_assert(
|
||||
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);
|
||||
kApiCommandLineVersion >= kApiMinimumSupportedVersion &&
|
||||
kApiCommandLineVersion <= kApiMaximumSupportedVersion);
|
||||
static_assert(kApiMaximumSupportedVersion >= kApiMinimumSupportedVersion);
|
||||
static_assert(kApiBetaVersion >= kApiMaximumSupportedVersion);
|
||||
static_assert(kApiMaximumValidVersion >= kApiMaximumSupportedVersion);
|
||||
|
||||
inline void
|
||||
setVersion(json::Value& parent, unsigned int apiVersion, bool betaEnabled)
|
||||
{
|
||||
XRPL_ASSERT(apiVersion != kAPI_INVALID_VERSION, "xrpl::RPC::setVersion : input is valid");
|
||||
XRPL_ASSERT(apiVersion != kApiInvalidVersion, "xrpl::RPC::setVersion : input is valid");
|
||||
|
||||
auto& retObj = parent[jss::version] = json::ValueType::Object;
|
||||
|
||||
if (apiVersion == kAPI_VERSION_IF_UNSPECIFIED)
|
||||
if (apiVersion == kApiVersionIfUnspecified)
|
||||
{
|
||||
// API version numbers used in API version 1
|
||||
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"};
|
||||
static beast::SemanticVersion const kFirstVersion{"1.0.0"};
|
||||
static beast::SemanticVersion const kGoodVersion{"1.0.0"};
|
||||
static beast::SemanticVersion const kLastVersion{"1.0.0"};
|
||||
|
||||
retObj[jss::first] = kFIRST_VERSION.print();
|
||||
retObj[jss::good] = kGOOD_VERSION.print();
|
||||
retObj[jss::last] = kLAST_VERSION.print();
|
||||
retObj[jss::first] = kFirstVersion.print();
|
||||
retObj[jss::good] = kGoodVersion.print();
|
||||
retObj[jss::last] = kLastVersion.print();
|
||||
}
|
||||
else
|
||||
{
|
||||
retObj[jss::first] = kAPI_MINIMUM_SUPPORTED_VERSION.value;
|
||||
retObj[jss::last] = betaEnabled ? kAPI_BETA_VERSION : kAPI_MAXIMUM_SUPPORTED_VERSION;
|
||||
retObj[jss::first] = kApiMinimumSupportedVersion.value;
|
||||
retObj[jss::last] = betaEnabled ? kApiBetaVersion : kApiMaximumSupportedVersion;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,9 +98,9 @@ setVersion(json::Value& parent, unsigned int apiVersion, bool betaEnabled)
|
||||
inline unsigned int
|
||||
getAPIVersionNumber(json::Value const& jv, bool betaEnabled)
|
||||
{
|
||||
static json::Value const kMIN_VERSION(RPC::kAPI_MINIMUM_SUPPORTED_VERSION);
|
||||
static json::Value const kMinVersion(RPC::kApiMinimumSupportedVersion);
|
||||
json::Value const maxVersion(
|
||||
betaEnabled ? RPC::kAPI_BETA_VERSION : RPC::kAPI_MAXIMUM_SUPPORTED_VERSION);
|
||||
betaEnabled ? RPC::kApiBetaVersion : RPC::kApiMaximumSupportedVersion);
|
||||
|
||||
if (jv.isObject())
|
||||
{
|
||||
@@ -109,18 +109,18 @@ getAPIVersionNumber(json::Value const& jv, bool betaEnabled)
|
||||
auto const specifiedVersion = jv[jss::api_version];
|
||||
if (!specifiedVersion.isInt() && !specifiedVersion.isUInt())
|
||||
{
|
||||
return RPC::kAPI_INVALID_VERSION;
|
||||
return RPC::kApiInvalidVersion;
|
||||
}
|
||||
auto const specifiedVersionInt = specifiedVersion.asInt();
|
||||
if (specifiedVersionInt < kMIN_VERSION || specifiedVersionInt > maxVersion)
|
||||
if (specifiedVersionInt < kMinVersion || specifiedVersionInt > maxVersion)
|
||||
{
|
||||
return RPC::kAPI_INVALID_VERSION;
|
||||
return RPC::kApiInvalidVersion;
|
||||
}
|
||||
return specifiedVersionInt;
|
||||
}
|
||||
}
|
||||
|
||||
return RPC::kAPI_VERSION_IF_UNSPECIFIED;
|
||||
return RPC::kApiVersionIfUnspecified;
|
||||
}
|
||||
|
||||
} // namespace RPC
|
||||
@@ -128,33 +128,33 @@ getAPIVersionNumber(json::Value const& jv, bool betaEnabled)
|
||||
template <unsigned MinVer, unsigned MaxVer, typename Fn, typename... Args>
|
||||
void
|
||||
forApiVersions(Fn const& fn, Args&&... args)
|
||||
requires //
|
||||
(MaxVer >= MinVer) && //
|
||||
(MinVer >= RPC::kAPI_MINIMUM_SUPPORTED_VERSION) && //
|
||||
(RPC::kAPI_MAXIMUM_VALID_VERSION >= MaxVer) && requires {
|
||||
requires //
|
||||
(MaxVer >= MinVer) && //
|
||||
(MinVer >= RPC::kApiMinimumSupportedVersion) && //
|
||||
(RPC::kApiMaximumValidVersion >= MaxVer) && requires {
|
||||
fn(std::integral_constant<unsigned int, MinVer>{}, std::forward<Args>(args)...);
|
||||
fn(std::integral_constant<unsigned int, MaxVer>{}, std::forward<Args>(args)...);
|
||||
}
|
||||
{
|
||||
constexpr auto kSIZE = MaxVer + 1 - MinVer;
|
||||
static constexpr auto kSize = MaxVer + 1 - MinVer;
|
||||
[&]<std::size_t... Offset>(std::index_sequence<Offset...>) {
|
||||
// NOLINTBEGIN(bugprone-use-after-move)
|
||||
(((void)fn(
|
||||
std::integral_constant<unsigned int, MinVer + Offset>{}, std::forward<Args>(args)...)),
|
||||
...);
|
||||
// NOLINTEND(bugprone-use-after-move)
|
||||
}(std::make_index_sequence<kSIZE>{});
|
||||
}(std::make_index_sequence<kSize>{});
|
||||
}
|
||||
|
||||
template <typename Fn, typename... Args>
|
||||
void
|
||||
forAllApiVersions(Fn const& fn, Args&&... args)
|
||||
requires requires {
|
||||
forApiVersions<RPC::kAPI_MINIMUM_SUPPORTED_VERSION, RPC::kAPI_MAXIMUM_VALID_VERSION>(
|
||||
forApiVersions<RPC::kApiMinimumSupportedVersion, RPC::kApiMaximumValidVersion>(
|
||||
fn, std::forward<Args>(args)...);
|
||||
}
|
||||
{
|
||||
forApiVersions<RPC::kAPI_MINIMUM_SUPPORTED_VERSION, RPC::kAPI_MAXIMUM_VALID_VERSION>(
|
||||
forApiVersions<RPC::kApiMinimumSupportedVersion, RPC::kApiMaximumValidVersion>(
|
||||
fn, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
|
||||
@@ -148,10 +148,10 @@ public:
|
||||
};
|
||||
|
||||
template <ValidIssueType TIss>
|
||||
constexpr bool kIS_ISSUE_V = std::is_same_v<TIss, Issue>;
|
||||
constexpr bool kIsIssueV = std::is_same_v<TIss, Issue>;
|
||||
|
||||
template <ValidIssueType TIss>
|
||||
constexpr bool kIS_MPTISSUE_V = std::is_same_v<TIss, MPTIssue>;
|
||||
constexpr bool kIsMptissueV = std::is_same_v<TIss, MPTIssue>;
|
||||
|
||||
inline json::Value
|
||||
toJson(Asset const& asset)
|
||||
@@ -242,7 +242,7 @@ operator<=>(Asset const& lhs, Asset const& rhs)
|
||||
{
|
||||
return std::weak_ordering(lhs <=> rhs);
|
||||
}
|
||||
else if constexpr (kIS_ISSUE_V<TLhs> && kIS_MPTISSUE_V<TRhs>)
|
||||
else if constexpr (kIsIssueV<TLhs> && kIsMptissueV<TRhs>)
|
||||
{
|
||||
return std::weak_ordering::greater;
|
||||
}
|
||||
|
||||
@@ -65,11 +65,11 @@
|
||||
namespace xrpl {
|
||||
|
||||
// Feature names must not exceed this length (in characters, excluding the null terminator).
|
||||
static constexpr std::size_t kMAX_FEATURE_NAME_SIZE = 63;
|
||||
static constexpr std::size_t kMaxFeatureNameSize = 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 kRESERVED_FEATURE_NAME_SIZE = 32;
|
||||
static constexpr std::size_t kReservedFeatureNameSize = 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
|
||||
@@ -81,14 +81,14 @@ validFeatureNameSize(auto fn) -> bool
|
||||
{
|
||||
constexpr char const* kN = fn();
|
||||
// Note, std::strlen is not constexpr, we need to implement our own here.
|
||||
constexpr std::size_t kLEN = [](auto n) {
|
||||
constexpr std::size_t kLen = [](auto n) {
|
||||
std::size_t ret = 0;
|
||||
for (auto ptr = n; *ptr != '\0'; ret++, ++ptr)
|
||||
;
|
||||
return ret;
|
||||
}(kN);
|
||||
return kLEN != kRESERVED_FEATURE_NAME_SIZE && //
|
||||
kLEN <= kMAX_FEATURE_NAME_SIZE;
|
||||
return kLen != kReservedFeatureNameSize && //
|
||||
kLen <= kMaxFeatureNameSize;
|
||||
}
|
||||
|
||||
consteval auto
|
||||
@@ -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 kNUM_FEATURES =
|
||||
static constexpr std::size_t kNumFeatures =
|
||||
(0 +
|
||||
#include <xrpl/protocol/detail/features.macro>
|
||||
);
|
||||
@@ -184,9 +184,9 @@ bitsetIndexToFeature(size_t i);
|
||||
std::string
|
||||
featureToName(uint256 const& f);
|
||||
|
||||
class FeatureBitset : private std::bitset<detail::kNUM_FEATURES>
|
||||
class FeatureBitset : private std::bitset<detail::kNumFeatures>
|
||||
{
|
||||
using base = std::bitset<detail::kNUM_FEATURES>;
|
||||
using base = std::bitset<detail::kNumFeatures>;
|
||||
|
||||
template <class... Fs>
|
||||
void
|
||||
|
||||
@@ -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 kFEE_UNITS_DEPRECATED = 10;
|
||||
inline constexpr std::uint32_t kFeeUnitsDeprecated = 10;
|
||||
|
||||
/** Reflects the fee settings for a particular ledger.
|
||||
|
||||
|
||||
@@ -92,7 +92,7 @@ public:
|
||||
|
||||
inline IOUAmount::IOUAmount(beast::Zero)
|
||||
{
|
||||
*this = beast::kZERO;
|
||||
*this = beast::kZero;
|
||||
}
|
||||
|
||||
inline IOUAmount::IOUAmount(mantissa_type mantissa, exponent_type exponent)
|
||||
|
||||
@@ -82,7 +82,7 @@ struct BookT
|
||||
Keylet
|
||||
operator()(Book const& b) const;
|
||||
};
|
||||
static BookT const kBOOK{};
|
||||
static BookT const kBook{};
|
||||
|
||||
/** The index of a trust line for a given currency
|
||||
|
||||
@@ -126,7 +126,7 @@ struct NextT
|
||||
Keylet
|
||||
operator()(Keylet const& k) const;
|
||||
};
|
||||
static NextT const kNEXT{};
|
||||
static NextT const kNext{};
|
||||
|
||||
/** A ticket belonging to an account */
|
||||
struct TicketT
|
||||
@@ -145,7 +145,7 @@ struct TicketT
|
||||
return {ltTICKET, key};
|
||||
}
|
||||
};
|
||||
static TicketT const kTICKET{};
|
||||
static TicketT const kTicket{};
|
||||
|
||||
/** A SignerList */
|
||||
Keylet
|
||||
@@ -287,7 +287,7 @@ credential(uint256 const& key) noexcept
|
||||
}
|
||||
|
||||
Keylet
|
||||
mptIssuance(std::uint32_t seq, AccountID const& issuer) noexcept;
|
||||
mptIssuance(std::uint32_t const seq, AccountID const& issuer) noexcept;
|
||||
|
||||
Keylet
|
||||
mptIssuance(MPTID const& issuanceID) noexcept;
|
||||
@@ -373,7 +373,7 @@ struct KeyletDesc
|
||||
|
||||
// This list should include all of the keylet functions that take a single
|
||||
// AccountID parameter.
|
||||
std::array<KeyletDesc<AccountID const&>, 6> const kDIRECT_ACCOUNT_KEYLETS{
|
||||
std::array<KeyletDesc<AccountID const&>, 6> const kDirectAccountKeylets{
|
||||
{{.function = &keylet::account, .expectedLEName = jss::AccountRoot, .includeInTests = false},
|
||||
{.function = &keylet::ownerDir, .expectedLEName = jss::DirectoryNode, .includeInTests = true},
|
||||
{.function = &keylet::signers, .expectedLEName = jss::SignerList, .includeInTests = true},
|
||||
|
||||
@@ -96,16 +96,16 @@ operator<=>(Issue const& lhs, Issue const& rhs)
|
||||
inline Issue const&
|
||||
xrpIssue()
|
||||
{
|
||||
static Issue const kISSUE{xrpCurrency(), xrpAccount()};
|
||||
return kISSUE;
|
||||
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 kISSUE{noCurrency(), noAccount()};
|
||||
return kISSUE;
|
||||
static Issue const kIssue{noCurrency(), noAccount()};
|
||||
return kIssue;
|
||||
}
|
||||
|
||||
inline bool
|
||||
|
||||
@@ -26,12 +26,12 @@ struct LedgerHeader
|
||||
//
|
||||
|
||||
// Closed means "tx set already determined"
|
||||
uint256 hash = beast::kZERO;
|
||||
uint256 txHash = beast::kZERO;
|
||||
uint256 accountHash = beast::kZERO;
|
||||
uint256 parentHash = beast::kZERO;
|
||||
uint256 hash = beast::kZero;
|
||||
uint256 txHash = beast::kZero;
|
||||
uint256 accountHash = beast::kZero;
|
||||
uint256 parentHash = beast::kZero;
|
||||
|
||||
XRPAmount drops = beast::kZERO;
|
||||
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 kS_LCF_NO_CONSENSUS_TIME = 0x01;
|
||||
static std::uint32_t const kSLcfNoConsensusTime = 0x01;
|
||||
|
||||
inline bool
|
||||
getCloseAgree(LedgerHeader const& info)
|
||||
{
|
||||
return (info.closeFlags & kS_LCF_NO_CONSENSUS_TIME) == 0;
|
||||
return (info.closeFlags & kSLcfNoConsensusTime) == 0;
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -88,7 +88,7 @@ constexpr MPTAmount::MPTAmount(value_type value) : value_(value)
|
||||
|
||||
constexpr MPTAmount::MPTAmount(beast::Zero)
|
||||
{
|
||||
*this = beast::kZERO;
|
||||
*this = beast::kZero;
|
||||
}
|
||||
|
||||
constexpr MPTAmount&
|
||||
|
||||
@@ -15,14 +15,14 @@ namespace xrpl {
|
||||
|
||||
namespace detail {
|
||||
template <typename T>
|
||||
constexpr bool kIS_INTEGRAL_CONSTANT = false;
|
||||
constexpr bool kIsIntegralConstant = false;
|
||||
template <typename I, auto A>
|
||||
constexpr bool kIS_INTEGRAL_CONSTANT<std::integral_constant<I, A>&> = true;
|
||||
constexpr bool kIsIntegralConstant<std::integral_constant<I, A>&> = true;
|
||||
template <typename I, auto A>
|
||||
constexpr bool kIS_INTEGRAL_CONSTANT<std::integral_constant<I, A> const&> = true;
|
||||
constexpr bool kIsIntegralConstant<std::integral_constant<I, A> const&> = true;
|
||||
|
||||
template <typename T>
|
||||
concept some_integral_constant = detail::kIS_INTEGRAL_CONSTANT<T&>;
|
||||
concept some_integral_constant = detail::kIsIntegralConstant<T&>;
|
||||
|
||||
// This class is designed to wrap a collection of _almost_ identical json::Value
|
||||
// objects, indexed by version (i.e. there is some mapping of version to object
|
||||
@@ -47,8 +47,8 @@ struct MultiApiJson
|
||||
return (v < MinVer) ? 0 : static_cast<std::size_t>(v - MinVer);
|
||||
}
|
||||
|
||||
constexpr static std::size_t kSIZE = MaxVer + 1 - MinVer;
|
||||
std::array<json::Value, kSIZE> val = {};
|
||||
static constexpr std::size_t kSize = MaxVer + 1 - MinVer;
|
||||
std::array<json::Value, kSize> val = {};
|
||||
|
||||
explicit MultiApiJson(json::Value const& init = {})
|
||||
{
|
||||
@@ -80,7 +80,7 @@ struct MultiApiJson
|
||||
|
||||
if (count == 0)
|
||||
return IsMemberResult::None;
|
||||
return count < kSIZE ? IsMemberResult::Some : IsMemberResult::All;
|
||||
return count < kSize ? IsMemberResult::Some : IsMemberResult::All;
|
||||
}
|
||||
|
||||
static constexpr struct VisitorT final
|
||||
@@ -100,7 +100,7 @@ struct MultiApiJson
|
||||
std::integral_constant<unsigned int, Version>,
|
||||
Args&&...>
|
||||
{
|
||||
static_assert(valid(Version) && index(Version) >= 0 && index(Version) < kSIZE);
|
||||
static_assert(valid(Version) && index(Version) >= 0 && index(Version) < kSize);
|
||||
return std::invoke(fn, json.val[index(Version)], version, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
@@ -111,7 +111,7 @@ struct MultiApiJson
|
||||
operator()(Json& json, std::integral_constant<unsigned int, Version> const, Fn fn) const
|
||||
-> std::invoke_result_t<Fn, decltype(json.val[0])>
|
||||
{
|
||||
static_assert(valid(Version) && index(Version) >= 0 && index(Version) < kSIZE);
|
||||
static_assert(valid(Version) && index(Version) >= 0 && index(Version) < kSize);
|
||||
return std::invoke(fn, json.val[index(Version)]);
|
||||
}
|
||||
|
||||
@@ -124,7 +124,7 @@ struct MultiApiJson
|
||||
-> std::invoke_result_t<Fn, decltype(json.val[0]), Version, Args&&...>
|
||||
{
|
||||
XRPL_ASSERT(
|
||||
valid(version) && index(version) >= 0 && index(version) < kSIZE,
|
||||
valid(version) && index(version) >= 0 && index(version) < kSize,
|
||||
"xrpl::detail::MultiApijson::operator<Args...>() : valid "
|
||||
"version");
|
||||
return std::invoke(fn, json.val[index(version)], version, std::forward<Args>(args)...);
|
||||
@@ -139,20 +139,20 @@ struct MultiApiJson
|
||||
-> std::invoke_result_t<Fn, decltype(json.val[0])>
|
||||
{
|
||||
XRPL_ASSERT(
|
||||
valid(version) && index(version) >= 0 && index(version) < kSIZE,
|
||||
valid(version) && index(version) >= 0 && index(version) < kSize,
|
||||
"xrpl::detail::MultiApijson::operator() : valid version");
|
||||
return std::invoke(fn, json.val[index(version)]);
|
||||
}
|
||||
} kVISITOR = {};
|
||||
} kVisitor = {};
|
||||
|
||||
auto
|
||||
visit()
|
||||
{
|
||||
return [self = this](auto... args)
|
||||
requires requires {
|
||||
kVISITOR(std::declval<MultiApiJson&>(), std::declval<decltype(args)>()...);
|
||||
kVisitor(std::declval<MultiApiJson&>(), std::declval<decltype(args)>()...);
|
||||
}
|
||||
{ return kVISITOR(*self, std::forward<decltype(args)>(args)...); };
|
||||
{ return kVisitor(*self, std::forward<decltype(args)>(args)...); };
|
||||
}
|
||||
|
||||
[[nodiscard]] auto
|
||||
@@ -160,27 +160,27 @@ struct MultiApiJson
|
||||
{
|
||||
return [self = this](auto... args)
|
||||
requires requires {
|
||||
kVISITOR(std::declval<MultiApiJson const&>(), std::declval<decltype(args)>()...);
|
||||
kVisitor(std::declval<MultiApiJson const&>(), std::declval<decltype(args)>()...);
|
||||
}
|
||||
{ return kVISITOR(*self, std::forward<decltype(args)>(args)...); };
|
||||
{ return kVisitor(*self, std::forward<decltype(args)>(args)...); };
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
auto
|
||||
visit(Args... args) -> std::invoke_result_t<VisitorT, MultiApiJson&, Args...>
|
||||
requires(sizeof...(args) > 0) &&
|
||||
requires { kVISITOR(*this, std::forward<decltype(args)>(args)...); }
|
||||
requires { kVisitor(*this, std::forward<decltype(args)>(args)...); }
|
||||
{
|
||||
return kVISITOR(*this, std::forward<decltype(args)>(args)...);
|
||||
return kVisitor(*this, std::forward<decltype(args)>(args)...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
[[nodiscard]] auto
|
||||
visit(Args... args) const -> std::invoke_result_t<VisitorT, MultiApiJson const&, Args...>
|
||||
requires(sizeof...(args) > 0) &&
|
||||
requires { kVISITOR(*this, std::forward<decltype(args)>(args)...); }
|
||||
requires { kVisitor(*this, std::forward<decltype(args)>(args)...); }
|
||||
{
|
||||
return kVISITOR(*this, std::forward<decltype(args)>(args)...);
|
||||
return kVisitor(*this, std::forward<decltype(args)>(args)...);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -188,6 +188,6 @@ struct MultiApiJson
|
||||
|
||||
// Wrapper for Json for all supported API versions.
|
||||
using MultiApiJson =
|
||||
detail::MultiApiJson<RPC::kAPI_MINIMUM_SUPPORTED_VERSION, RPC::kAPI_MAXIMUM_VALID_VERSION>;
|
||||
detail::MultiApiJson<RPC::kApiMinimumSupportedVersion, RPC::kApiMaximumValidVersion>;
|
||||
|
||||
} // namespace xrpl
|
||||
|
||||
@@ -52,10 +52,10 @@ public:
|
||||
};
|
||||
|
||||
template <ValidPathAsset PA>
|
||||
constexpr bool kIS_CURRENCY_V = std::is_same_v<PA, Currency>;
|
||||
constexpr bool kIsCurrencyV = std::is_same_v<PA, Currency>;
|
||||
|
||||
template <ValidPathAsset PA>
|
||||
constexpr bool kIS_MPTID_V = std::is_same_v<PA, MPTID>;
|
||||
constexpr bool kIsMptidV = std::is_same_v<PA, MPTID>;
|
||||
|
||||
inline PathAsset::PathAsset(Asset const& asset)
|
||||
{
|
||||
|
||||
@@ -19,40 +19,40 @@ namespace xrpl {
|
||||
@ingroup protocol
|
||||
*/
|
||||
/** Smallest legal byte size of a transaction. */
|
||||
std::size_t constexpr kTX_MIN_SIZE_BYTES = 32;
|
||||
constexpr std::size_t kTxMinSizeBytes = 32;
|
||||
|
||||
/** Largest legal byte size of a transaction. */
|
||||
std::size_t constexpr kTX_MAX_SIZE_BYTES = megabytes(1);
|
||||
constexpr std::size_t kTxMaxSizeBytes = megabytes(1);
|
||||
|
||||
/** The maximum number of unfunded offers to delete at once */
|
||||
std::size_t constexpr kUNFUNDED_OFFER_REMOVE_LIMIT = 1000;
|
||||
constexpr std::size_t kUnfundedOfferRemoveLimit = 1000;
|
||||
|
||||
/** The maximum number of expired offers to delete at once */
|
||||
std::size_t constexpr kEXPIRED_OFFER_REMOVE_LIMIT = 256;
|
||||
constexpr std::size_t kExpiredOfferRemoveLimit = 256;
|
||||
|
||||
/** The maximum number of metadata entries allowed in one transaction */
|
||||
std::size_t constexpr kOVERSIZE_META_DATA_CAP = 5200;
|
||||
constexpr std::size_t kOversizeMetaDataCap = 5200;
|
||||
|
||||
/** The maximum number of entries per directory page */
|
||||
std::size_t constexpr kDIR_NODE_MAX_ENTRIES = 32;
|
||||
constexpr std::size_t kDirNodeMaxEntries = 32;
|
||||
|
||||
/** The maximum number of pages allowed in a directory
|
||||
|
||||
Made obsolete by fixDirectoryLimit amendment.
|
||||
*/
|
||||
std::uint64_t constexpr kDIR_NODE_MAX_PAGES = 262144;
|
||||
constexpr std::uint64_t kDirNodeMaxPages = 262144;
|
||||
|
||||
/** The maximum number of items in an NFT page */
|
||||
std::size_t constexpr kDIR_MAX_TOKENS_PER_PAGE = 32;
|
||||
constexpr std::size_t kDirMaxTokensPerPage = 32;
|
||||
|
||||
/** The maximum number of owner directory entries for account to be deletable */
|
||||
std::size_t constexpr kMAX_DELETABLE_DIR_ENTRIES = 1000;
|
||||
constexpr std::size_t kMaxDeletableDirEntries = 1000;
|
||||
|
||||
/** The maximum number of token offers that can be canceled at once */
|
||||
std::size_t constexpr kMAX_TOKEN_OFFER_CANCEL_COUNT = 500;
|
||||
constexpr std::size_t kMaxTokenOfferCancelCount = 500;
|
||||
|
||||
/** The maximum number of offers in an offer directory for NFT to be burnable */
|
||||
std::size_t constexpr kMAX_DELETABLE_TOKEN_OFFER_ENTRIES = 500;
|
||||
constexpr std::size_t kMaxDeletableTokenOfferEntries = 500;
|
||||
|
||||
/** The maximum token transfer fee allowed.
|
||||
|
||||
@@ -63,7 +63,7 @@ std::size_t constexpr kMAX_DELETABLE_TOKEN_OFFER_ENTRIES = 500;
|
||||
Note that for extremely low transfer fees values, it is possible that the
|
||||
calculated fee will be 0.
|
||||
*/
|
||||
std::uint16_t constexpr kMAX_TRANSFER_FEE = 50000;
|
||||
constexpr std::uint16_t kMaxTransferFee = 50000;
|
||||
|
||||
/** There are 10,000 basis points (bips) in 100%.
|
||||
*
|
||||
@@ -81,32 +81,32 @@ std::uint16_t constexpr kMAX_TRANSFER_FEE = 50000;
|
||||
*
|
||||
* Example: 50% is 0.50 * bipsPerUnity = 5,000 bps.
|
||||
*/
|
||||
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 kBipsPerUnity(100 * 100);
|
||||
static_assert(kBipsPerUnity == Bips32{10'000});
|
||||
constexpr TenthBips32 kTenthBipsPerUnity(kBipsPerUnity.value() * 10);
|
||||
static_assert(kTenthBipsPerUnity == TenthBips32(100'000));
|
||||
|
||||
constexpr Bips32
|
||||
percentageToBips(std::uint32_t percentage)
|
||||
{
|
||||
return Bips32(percentage * kBIPS_PER_UNITY.value() / 100);
|
||||
return Bips32(percentage * kBipsPerUnity.value() / 100);
|
||||
}
|
||||
constexpr TenthBips32
|
||||
percentageToTenthBips(std::uint32_t percentage)
|
||||
{
|
||||
return TenthBips32(percentage * kTENTH_BIPS_PER_UNITY.value() / 100);
|
||||
return TenthBips32(percentage * kTenthBipsPerUnity.value() / 100);
|
||||
}
|
||||
template <typename T, class TBips>
|
||||
constexpr T
|
||||
bipsOfValue(T value, Bips<TBips> bips)
|
||||
{
|
||||
return value * bips.value() / kBIPS_PER_UNITY.value();
|
||||
return value * bips.value() / kBipsPerUnity.value();
|
||||
}
|
||||
template <typename T, class TBips>
|
||||
constexpr T
|
||||
tenthBipsOfValue(T value, TenthBips<TBips> bips)
|
||||
{
|
||||
return value * bips.value() / kTENTH_BIPS_PER_UNITY.value();
|
||||
return value * bips.value() / kTenthBipsPerUnity.value();
|
||||
}
|
||||
|
||||
namespace Lending {
|
||||
@@ -114,54 +114,54 @@ namespace Lending {
|
||||
|
||||
Valid values are between 0 and 10% inclusive.
|
||||
*/
|
||||
TenthBips16 constexpr kMAX_MANAGEMENT_FEE_RATE(
|
||||
constexpr TenthBips16 kMaxManagementFeeRate(
|
||||
unsafeCast<std::uint16_t>(percentageToTenthBips(10).value()));
|
||||
static_assert(kMAX_MANAGEMENT_FEE_RATE == TenthBips16(std::uint16_t(10'000u)));
|
||||
static_assert(kMaxManagementFeeRate == 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 kMAX_COVER_RATE = percentageToTenthBips(100);
|
||||
static_assert(kMAX_COVER_RATE == TenthBips32(100'000u));
|
||||
constexpr TenthBips32 kMaxCoverRate = percentageToTenthBips(100);
|
||||
static_assert(kMaxCoverRate == TenthBips32(100'000u));
|
||||
|
||||
/** The maximum overpayment fee on a loan in 1/10 bips.
|
||||
*
|
||||
Valid values are between 0 and 100% inclusive.
|
||||
*/
|
||||
TenthBips32 constexpr kMAX_OVERPAYMENT_FEE = percentageToTenthBips(100);
|
||||
static_assert(kMAX_OVERPAYMENT_FEE == TenthBips32(100'000u));
|
||||
constexpr TenthBips32 kMaxOverpaymentFee = percentageToTenthBips(100);
|
||||
static_assert(kMaxOverpaymentFee == TenthBips32(100'000u));
|
||||
|
||||
/** Annualized interest rate of the Loan in 1/10 bips.
|
||||
*
|
||||
* Valid values are between 0 and 100% inclusive.
|
||||
*/
|
||||
TenthBips32 constexpr kMAX_INTEREST_RATE = percentageToTenthBips(100);
|
||||
static_assert(kMAX_INTEREST_RATE == TenthBips32(100'000u));
|
||||
constexpr TenthBips32 kMaxInterestRate = percentageToTenthBips(100);
|
||||
static_assert(kMaxInterestRate == 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 kMAX_LATE_INTEREST_RATE = percentageToTenthBips(100);
|
||||
static_assert(kMAX_LATE_INTEREST_RATE == TenthBips32(100'000u));
|
||||
constexpr TenthBips32 kMaxLateInterestRate = percentageToTenthBips(100);
|
||||
static_assert(kMaxLateInterestRate == 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 kMAX_CLOSE_INTEREST_RATE = percentageToTenthBips(100);
|
||||
static_assert(kMAX_CLOSE_INTEREST_RATE == TenthBips32(100'000u));
|
||||
constexpr TenthBips32 kMaxCloseInterestRate = percentageToTenthBips(100);
|
||||
static_assert(kMaxCloseInterestRate == 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 kMAX_OVERPAYMENT_INTEREST_RATE = percentageToTenthBips(100);
|
||||
static_assert(kMAX_OVERPAYMENT_INTEREST_RATE == TenthBips32(100'000u));
|
||||
constexpr TenthBips32 kMaxOverpaymentInterestRate = percentageToTenthBips(100);
|
||||
static_assert(kMaxOverpaymentInterestRate == TenthBips32(100'000u));
|
||||
|
||||
/** LoanPay transaction cost will be one base fee per X combined payments
|
||||
*
|
||||
@@ -172,7 +172,7 @@ static_assert(kMAX_OVERPAYMENT_INTEREST_RATE == TenthBips32(100'000u));
|
||||
* This number was chosen arbitrarily, but should not be changed once released
|
||||
* without an amendment
|
||||
*/
|
||||
static constexpr int kLOAN_PAYMENTS_PER_FEE_INCREMENT = 5;
|
||||
static constexpr int kLoanPaymentsPerFeeIncrement = 5;
|
||||
|
||||
/** Maximum number of combined payments that a LoanPay transaction will process
|
||||
*
|
||||
@@ -196,65 +196,65 @@ static constexpr int kLOAN_PAYMENTS_PER_FEE_INCREMENT = 5;
|
||||
* This number was chosen arbitrarily, but should not be changed once released
|
||||
* without an amendment
|
||||
*/
|
||||
static constexpr int kLOAN_MAXIMUM_PAYMENTS_PER_TRANSACTION = 100;
|
||||
static constexpr int kLoanMaximumPaymentsPerTransaction = 100;
|
||||
} // namespace Lending
|
||||
|
||||
/** The maximum length of a URI inside an NFT */
|
||||
std::size_t constexpr kMAX_TOKEN_URI_LENGTH = 256;
|
||||
constexpr std::size_t kMaxTokenUriLength = 256;
|
||||
|
||||
/** The maximum length of a Data element inside a DID */
|
||||
std::size_t constexpr kMAX_DID_DOCUMENT_LENGTH = 256;
|
||||
constexpr std::size_t kMaxDidDocumentLength = 256;
|
||||
|
||||
/** The maximum length of a URI inside a DID */
|
||||
std::size_t constexpr kMAX_DIDURI_LENGTH = 256;
|
||||
constexpr std::size_t kMaxDidUriLength = 256;
|
||||
|
||||
/** The maximum length of an Attestation inside a DID */
|
||||
std::size_t constexpr kMAX_DID_DATA_LENGTH = 256;
|
||||
constexpr std::size_t kMaxDidDataLength = 256;
|
||||
|
||||
/** The maximum length of a domain */
|
||||
std::size_t constexpr kMAX_DOMAIN_LENGTH = 256;
|
||||
constexpr std::size_t kMaxDomainLength = 256;
|
||||
|
||||
/** The maximum length of a URI inside a Credential */
|
||||
std::size_t constexpr kMAX_CREDENTIAL_URI_LENGTH = 256;
|
||||
constexpr std::size_t kMaxCredentialUriLength = 256;
|
||||
|
||||
/** The maximum length of a CredentialType inside a Credential */
|
||||
std::size_t constexpr kMAX_CREDENTIAL_TYPE_LENGTH = 64;
|
||||
constexpr std::size_t kMaxCredentialTypeLength = 64;
|
||||
|
||||
/** The maximum number of credentials can be passed in array */
|
||||
std::size_t constexpr kMAX_CREDENTIALS_ARRAY_SIZE = 8;
|
||||
constexpr std::size_t kMaxCredentialsArraySize = 8;
|
||||
|
||||
/** The maximum number of credentials can be passed in array for permissioned
|
||||
* domain */
|
||||
std::size_t constexpr kMAX_PERMISSIONED_DOMAIN_CREDENTIALS_ARRAY_SIZE = 10;
|
||||
constexpr std::size_t kMaxPermissionedDomainCredentialsArraySize = 10;
|
||||
|
||||
/** The maximum length of MPTokenMetadata */
|
||||
std::size_t constexpr kMAX_MP_TOKEN_METADATA_LENGTH = 1024;
|
||||
constexpr std::size_t kMaxMpTokenMetadataLength = 1024;
|
||||
|
||||
/** The maximum amount of MPTokenIssuance */
|
||||
std::uint64_t constexpr kMAX_MP_TOKEN_AMOUNT = 0x7FFF'FFFF'FFFF'FFFFull;
|
||||
static_assert(Number::kMAX_REP >= kMAX_MP_TOKEN_AMOUNT);
|
||||
constexpr std::uint64_t kMaxMpTokenAmount = 0x7FFF'FFFF'FFFF'FFFFull;
|
||||
static_assert(Number::kMaxRep >= kMaxMpTokenAmount);
|
||||
|
||||
/** The maximum length of Data payload */
|
||||
std::size_t constexpr kMAX_DATA_PAYLOAD_LENGTH = 256;
|
||||
constexpr std::size_t kMaxDataPayloadLength = 256;
|
||||
|
||||
/** Vault withdrawal policies */
|
||||
std::uint8_t constexpr kVAULT_STRATEGY_FIRST_COME_FIRST_SERVE = 1;
|
||||
constexpr std::uint8_t kVaultStrategyFirstComeFirstServe = 1;
|
||||
|
||||
/** Default IOU scale factor for a Vault */
|
||||
std::uint8_t constexpr kVAULT_DEFAULT_IOU_SCALE = 6;
|
||||
constexpr std::uint8_t kVaultDefaultIouScale = 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 kVAULT_MAXIMUM_IOU_SCALE = 18;
|
||||
constexpr std::uint8_t kVaultMaximumIouScale = 18;
|
||||
|
||||
/** Maximum recursion depth for vault shares being put as an asset inside
|
||||
* another vault; counted from 0 */
|
||||
std::uint8_t constexpr kMAX_ASSET_CHECK_DEPTH = 5;
|
||||
constexpr std::uint8_t kMaxAssetCheckDepth = 5;
|
||||
|
||||
/** A ledger index. */
|
||||
using LedgerIndex = std::uint32_t;
|
||||
|
||||
std::uint32_t constexpr kFLAG_LEDGER_INTERVAL = 256;
|
||||
constexpr std::uint32_t kFlagLedgerInterval = 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 kMAX_DELETABLE_AMM_TRUST_LINES = 512;
|
||||
constexpr std::uint16_t kMaxDeletableAmmTrustLines = 512;
|
||||
|
||||
/** The maximum length of a URI inside an Oracle */
|
||||
std::size_t constexpr kMAX_ORACLE_URI = 256;
|
||||
constexpr std::size_t kMaxOracleUri = 256;
|
||||
|
||||
/** The maximum length of a Provider inside an Oracle */
|
||||
std::size_t constexpr kMAX_ORACLE_PROVIDER = 256;
|
||||
constexpr std::size_t kMaxOracleProvider = 256;
|
||||
|
||||
/** The maximum size of a data series array inside an Oracle */
|
||||
std::size_t constexpr kMAX_ORACLE_DATA_SERIES = 10;
|
||||
constexpr std::size_t kMaxOracleDataSeries = 10;
|
||||
|
||||
/** The maximum length of a SymbolClass inside an Oracle */
|
||||
std::size_t constexpr kMAX_ORACLE_SYMBOL_CLASS = 16;
|
||||
constexpr std::size_t kMaxOracleSymbolClass = 16;
|
||||
|
||||
/** The maximum allowed time difference between lastUpdateTime and the time
|
||||
of the last closed ledger
|
||||
*/
|
||||
std::size_t constexpr kMAX_LAST_UPDATE_TIME_DELTA = 300;
|
||||
constexpr std::size_t kMaxLastUpdateTimeDelta = 300;
|
||||
|
||||
/** The maximum price scaling factor
|
||||
*/
|
||||
std::size_t constexpr kMAX_PRICE_SCALE = 20;
|
||||
constexpr std::size_t kMaxPriceScale = 20;
|
||||
|
||||
/** The maximum percentage of outliers to trim
|
||||
*/
|
||||
std::size_t constexpr kMAX_TRIM = 25;
|
||||
constexpr std::size_t kMaxTrim = 25;
|
||||
|
||||
/** The maximum number of delegate permissions an account can grant
|
||||
*/
|
||||
std::size_t constexpr kPERMISSION_MAX_SIZE = 10;
|
||||
constexpr std::size_t kPermissionMaxSize = 10;
|
||||
|
||||
/** The maximum number of transactions that can be in a batch. */
|
||||
std::size_t constexpr kMAX_BATCH_TX_COUNT = 8;
|
||||
constexpr std::size_t kMaxBatchTxCount = 8;
|
||||
|
||||
} // namespace xrpl
|
||||
|
||||
@@ -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 kSIZE = 33;
|
||||
std::uint8_t buf_[kSIZE]{}; // 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 kSIZE;
|
||||
return kSize;
|
||||
}
|
||||
|
||||
[[nodiscard]] const_iterator
|
||||
@@ -90,19 +90,19 @@ public:
|
||||
[[nodiscard]] const_iterator
|
||||
end() const noexcept
|
||||
{
|
||||
return buf_ + kSIZE;
|
||||
return buf_ + kSize;
|
||||
}
|
||||
|
||||
[[nodiscard]] const_iterator
|
||||
cend() const noexcept
|
||||
{
|
||||
return buf_ + kSIZE;
|
||||
return buf_ + kSize;
|
||||
}
|
||||
|
||||
[[nodiscard]] Slice
|
||||
slice() const noexcept
|
||||
{
|
||||
return {buf_, kSIZE};
|
||||
return {buf_, kSize};
|
||||
}
|
||||
|
||||
operator Slice() const noexcept
|
||||
|
||||
@@ -26,7 +26,7 @@ struct TAmounts
|
||||
{
|
||||
TAmounts() = default;
|
||||
|
||||
TAmounts(beast::Zero, beast::Zero) : in(beast::kZERO), out(beast::kZERO)
|
||||
TAmounts(beast::Zero, beast::Zero) : in(beast::kZero), out(beast::kZero)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ struct TAmounts
|
||||
[[nodiscard]] bool
|
||||
empty() const noexcept
|
||||
{
|
||||
return in <= beast::kZERO || out <= beast::kZERO;
|
||||
return in <= beast::kZero || out <= beast::kZero;
|
||||
}
|
||||
|
||||
TAmounts&
|
||||
@@ -94,8 +94,8 @@ public:
|
||||
// have lower unsigned integer representations.
|
||||
using value_type = std::uint64_t;
|
||||
|
||||
static int const kMIN_TICK_SIZE = 3;
|
||||
static int const kMAX_TICK_SIZE = 16;
|
||||
static int const kMinTickSize = 3;
|
||||
static int const kMaxTickSize = 16;
|
||||
|
||||
private:
|
||||
// This has the same representation as STAmount, see the comment on the
|
||||
@@ -316,10 +316,10 @@ TAmounts<In, Out>
|
||||
Quality::ceilIn(TAmounts<In, Out> const& amount, In const& limit) const
|
||||
{
|
||||
// Construct a function pointer to the function we want to call.
|
||||
static constexpr Amounts (Quality::*kCEIL_IN_FN_PTR)(Amounts const&, STAmount const&) const =
|
||||
static constexpr Amounts (Quality::*kCeilInFnPtr)(Amounts const&, STAmount const&) const =
|
||||
&Quality::ceilIn;
|
||||
|
||||
return ceilTAmountsHelper(amount, limit, amount.in, kCEIL_IN_FN_PTR);
|
||||
return ceilTAmountsHelper(amount, limit, amount.in, kCeilInFnPtr);
|
||||
}
|
||||
|
||||
template <class In, class Out>
|
||||
@@ -327,10 +327,10 @@ TAmounts<In, Out>
|
||||
Quality::ceilInStrict(TAmounts<In, Out> const& amount, In const& limit, bool roundUp) const
|
||||
{
|
||||
// Construct a function pointer to the function we want to call.
|
||||
static constexpr Amounts (Quality::*kCEIL_IN_FN_PTR)(Amounts const&, STAmount const&, bool)
|
||||
const = &Quality::ceilInStrict;
|
||||
static constexpr Amounts (Quality::*kCeilInFnPtr)(Amounts const&, STAmount const&, bool) const =
|
||||
&Quality::ceilInStrict;
|
||||
|
||||
return ceilTAmountsHelper(amount, limit, amount.in, kCEIL_IN_FN_PTR, roundUp);
|
||||
return ceilTAmountsHelper(amount, limit, amount.in, kCeilInFnPtr, roundUp);
|
||||
}
|
||||
|
||||
template <class In, class Out>
|
||||
@@ -338,10 +338,10 @@ TAmounts<In, Out>
|
||||
Quality::ceilOut(TAmounts<In, Out> const& amount, Out const& limit) const
|
||||
{
|
||||
// Construct a function pointer to the function we want to call.
|
||||
static constexpr Amounts (Quality::*kCEIL_OUT_FN_PTR)(Amounts const&, STAmount const&) const =
|
||||
static constexpr Amounts (Quality::*kCeilOutFnPtr)(Amounts const&, STAmount const&) const =
|
||||
&Quality::ceilOut;
|
||||
|
||||
return ceil_TAmounts_helper(amount, limit, amount.out, kCEIL_OUT_FN_PTR);
|
||||
return ceil_TAmounts_helper(amount, limit, amount.out, kCeilOutFnPtr);
|
||||
}
|
||||
|
||||
template <class In, class Out>
|
||||
@@ -349,10 +349,10 @@ TAmounts<In, Out>
|
||||
Quality::ceilOutStrict(TAmounts<In, Out> const& amount, Out const& limit, bool roundUp) const
|
||||
{
|
||||
// Construct a function pointer to the function we want to call.
|
||||
static constexpr Amounts (Quality::*kCEIL_OUT_FN_PTR)(Amounts const&, STAmount const&, bool)
|
||||
static constexpr Amounts (Quality::*kCeilOutFnPtr)(Amounts const&, STAmount const&, bool)
|
||||
const = &Quality::ceilOutStrict;
|
||||
|
||||
return ceilTAmountsHelper(amount, limit, amount.out, kCEIL_OUT_FN_PTR, roundUp);
|
||||
return ceilTAmountsHelper(amount, limit, amount.out, kCeilOutFnPtr, roundUp);
|
||||
}
|
||||
|
||||
/** Calculate the quality of a two-hop path given the two hops.
|
||||
|
||||
@@ -72,7 +72,7 @@ QualityFunction::QualityFunction(
|
||||
std::uint32_t tfee,
|
||||
QualityFunction::AMMTag)
|
||||
{
|
||||
if (amounts.in <= beast::kZERO || amounts.out <= beast::kZERO)
|
||||
if (amounts.in <= beast::kZero || amounts.out <= beast::kZero)
|
||||
Throw<std::runtime_error>("QualityFunction amounts are 0.");
|
||||
Number const cfee = feeMult(tfee);
|
||||
m_ = -cfee / amounts.in;
|
||||
|
||||
@@ -72,6 +72,6 @@ transferFeeAsRate(std::uint16_t fee);
|
||||
} // namespace nft
|
||||
|
||||
/** A transfer rate signifying a 1:1 exchange */
|
||||
extern Rate const kPARITY_RATE;
|
||||
extern Rate const kParityRate;
|
||||
|
||||
} // namespace xrpl
|
||||
|
||||
@@ -92,7 +92,7 @@ class STCurrency;
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
|
||||
enum SerializedTypeID { XMACRO(TO_ENUM) };
|
||||
|
||||
static std::map<std::string, int> const kS_TYPE_MAP = {XMACRO(TO_MAP)};
|
||||
static std::map<std::string, int> const kSTypeMap = {XMACRO(TO_MAP)};
|
||||
|
||||
#undef XMACRO
|
||||
#undef TO_ENUM
|
||||
@@ -129,23 +129,23 @@ fieldCode(int id, int index)
|
||||
class SField
|
||||
{
|
||||
public:
|
||||
static constexpr auto kSMD_NEVER = 0x00;
|
||||
static constexpr auto kSMD_CHANGE_ORIG = 0x01; // original value when it changes
|
||||
static constexpr auto kSMD_CHANGE_NEW = 0x02; // new value when it changes
|
||||
static constexpr auto kSMD_DELETE_FINAL = 0x04; // final value when it is deleted
|
||||
static constexpr auto kSMD_CREATE = 0x08; // value when it's created
|
||||
static constexpr auto kSMD_ALWAYS = 0x10; // value when node containing it is affected at all
|
||||
static constexpr auto kSMD_BASE_TEN = 0x20; // value is treated as base 10, overriding behavior
|
||||
static constexpr auto kSMD_PSEUDO_ACCOUNT = 0x40; // if this field is set in an ACCOUNT_ROOT
|
||||
// _only_, then it is a pseudo-account
|
||||
static constexpr auto kSMD_NEEDS_ASSET = 0x80; // This field needs to be associated with an
|
||||
// asset before it is serialized as a ledger
|
||||
// object. Intended for STNumber.
|
||||
static constexpr auto kSMD_DEFAULT =
|
||||
kSMD_CHANGE_ORIG | kSMD_CHANGE_NEW | kSMD_DELETE_FINAL | kSMD_CREATE;
|
||||
static constexpr auto kSmdNever = 0x00;
|
||||
static constexpr auto kSmdChangeOrig = 0x01; // original value when it changes
|
||||
static constexpr auto kSmdChangeNew = 0x02; // new value when it changes
|
||||
static constexpr auto kSmdDeleteFinal = 0x04; // final value when it is deleted
|
||||
static constexpr auto kSmdCreate = 0x08; // value when it's created
|
||||
static constexpr auto kSmdAlways = 0x10; // value when node containing it is affected at all
|
||||
static constexpr auto kSmdBaseTen = 0x20; // value is treated as base 10, overriding behavior
|
||||
static constexpr auto kSmdPseudoAccount = 0x40; // if this field is set in an ACCOUNT_ROOT
|
||||
// _only_, then it is a pseudo-account
|
||||
static constexpr auto kSmdNeedsAsset = 0x80; // This field needs to be associated with an
|
||||
// asset before it is serialized as a ledger
|
||||
// object. Intended for STNumber.
|
||||
static constexpr auto kSmdDefault =
|
||||
kSmdChangeOrig | kSmdChangeNew | kSmdDeleteFinal | kSmdCreate;
|
||||
|
||||
enum class IsSigning : unsigned char { No, Yes };
|
||||
static IsSigning const kNOT_SIGNING = IsSigning::No;
|
||||
static IsSigning const kNotSigning = IsSigning::No;
|
||||
|
||||
int const fieldCodeMem; // (type<<16)|index // TODO: rename, clashes with function
|
||||
SerializedTypeID const fieldType; // STI_*
|
||||
@@ -172,7 +172,7 @@ public:
|
||||
SerializedTypeID tid,
|
||||
int fv,
|
||||
char const* fn,
|
||||
int meta = kSMD_DEFAULT,
|
||||
int meta = kSmdDefault,
|
||||
IsSigning signing = IsSigning::Yes);
|
||||
explicit SField(PrivateAccessTagT, int fc, char const* fn);
|
||||
|
||||
@@ -365,8 +365,8 @@ using SF_XCHAIN_BRIDGE = TypedField<STXChainBridge>;
|
||||
#define UNTYPED_SFIELD(sfName, stiSuffix, fieldValue, ...) extern SField const sfName;
|
||||
#define TYPED_SFIELD(sfName, stiSuffix, fieldValue, ...) extern SF_##stiSuffix const sfName;
|
||||
|
||||
extern SField const kSF_INVALID;
|
||||
extern SField const kSF_GENERIC;
|
||||
extern SField const kSfInvalid;
|
||||
extern SField const kSfGeneric;
|
||||
|
||||
#include <xrpl/protocol/detail/sfields.macro>
|
||||
|
||||
|
||||
@@ -42,24 +42,24 @@ private:
|
||||
public:
|
||||
using value_type = STAmount;
|
||||
|
||||
constexpr static int kMIN_OFFSET = -96;
|
||||
constexpr static int kMAX_OFFSET = 80;
|
||||
static constexpr int kMinOffset = -96;
|
||||
static constexpr int kMaxOffset = 80;
|
||||
|
||||
// Maximum native value supported by the code
|
||||
constexpr static std::uint64_t kMIN_VALUE = 1'000'000'000'000'000ull;
|
||||
static_assert(isPowerOfTen(kMIN_VALUE));
|
||||
constexpr static std::uint64_t kMAX_VALUE = (kMIN_VALUE * 10) - 1;
|
||||
static_assert(kMAX_VALUE == 9'999'999'999'999'999ull);
|
||||
constexpr static std::uint64_t kMAX_NATIVE = 9'000'000'000'000'000'000ull;
|
||||
static constexpr std::uint64_t kMinValue = 1'000'000'000'000'000ull;
|
||||
static_assert(isPowerOfTen(kMinValue));
|
||||
static constexpr std::uint64_t kMaxValue = (kMinValue * 10) - 1;
|
||||
static_assert(kMaxValue == 9'999'999'999'999'999ull);
|
||||
static constexpr std::uint64_t kMaxNative = 9'000'000'000'000'000'000ull;
|
||||
|
||||
// Max native value on network.
|
||||
constexpr static std::uint64_t kMAX_NATIVE_N = 100'000'000'000'000'000ull;
|
||||
constexpr static std::uint64_t kISSUED_CURRENCY = 0x8'000'000'000'000'000ull;
|
||||
constexpr static std::uint64_t kPOSITIVE = 0x4'000'000'000'000'000ull;
|
||||
constexpr static std::uint64_t kMP_TOKEN = 0x2'000'000'000'000'000ull;
|
||||
constexpr static std::uint64_t kVALUE_MASK = ~(kPOSITIVE | kMP_TOKEN);
|
||||
static constexpr std::uint64_t kMaxNativeN = 100'000'000'000'000'000ull;
|
||||
static constexpr std::uint64_t kIssuedCurrency = 0x8'000'000'000'000'000ull;
|
||||
static constexpr std::uint64_t kPositive = 0x4'000'000'000'000'000ull;
|
||||
static constexpr std::uint64_t kMpToken = 0x2'000'000'000'000'000ull;
|
||||
static constexpr std::uint64_t kValueMask = ~(kPositive | kMpToken);
|
||||
|
||||
static std::uint64_t const kU_RATE_ONE;
|
||||
static std::uint64_t const kURateOne;
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
STAmount(SerialIter& sit, SField const& name);
|
||||
@@ -356,7 +356,7 @@ STAmount::STAmount(A const& asset, int mantissa, int exponent)
|
||||
|
||||
// Legacy support for new-style amounts
|
||||
inline STAmount::STAmount(IOUAmount const& amount, Issue const& issue)
|
||||
: asset_(issue), offset_(amount.exponent()), isNegative_(amount < beast::kZERO)
|
||||
: asset_(issue), offset_(amount.exponent()), isNegative_(amount < beast::kZero)
|
||||
{
|
||||
if (isNegative_)
|
||||
{
|
||||
@@ -371,7 +371,7 @@ inline STAmount::STAmount(IOUAmount const& amount, Issue const& issue)
|
||||
}
|
||||
|
||||
inline STAmount::STAmount(MPTAmount const& amount, MPTIssue const& mptIssue)
|
||||
: asset_(mptIssue), offset_(0), isNegative_(amount < beast::kZERO)
|
||||
: asset_(mptIssue), offset_(0), isNegative_(amount < beast::kZero)
|
||||
{
|
||||
if (isNegative_)
|
||||
{
|
||||
@@ -498,7 +498,7 @@ STAmount::zeroed() const
|
||||
inline STAmount::
|
||||
operator bool() const noexcept
|
||||
{
|
||||
return *this != beast::kZERO;
|
||||
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(kMIN_VALUE, kMAX_VALUE);
|
||||
auto const [mantissa, exponent] = working.normalizeToRange(kMinValue, kMaxValue);
|
||||
|
||||
return STAmount{asset, mantissa, exponent, negative};
|
||||
}
|
||||
@@ -548,7 +548,7 @@ STAmount::fromNumber(A const& a, Number const& number)
|
||||
inline void
|
||||
STAmount::negate()
|
||||
{
|
||||
if (*this != beast::kZERO)
|
||||
if (*this != beast::kZero)
|
||||
isNegative_ = !isNegative_;
|
||||
}
|
||||
|
||||
@@ -578,7 +578,7 @@ STAmount::value() const noexcept
|
||||
inline bool
|
||||
isLegalNet(STAmount const& value)
|
||||
{
|
||||
return !value.native() || (value.mantissa() <= STAmount::kMAX_NATIVE_N);
|
||||
return !value.native() || (value.mantissa() <= STAmount::kMaxNativeN);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
@@ -65,7 +65,7 @@ struct JsonOptions
|
||||
}
|
||||
|
||||
/// Returns JsonOptions binary negation, can be used with & (above) for set
|
||||
/// difference e.g. `(options & ~JsonOptions::kINCLUDE_DATE)`
|
||||
/// difference e.g. `(options & ~JsonOptions::kIncludeDate)`
|
||||
[[nodiscard]] constexpr JsonOptions friend
|
||||
operator~(JsonOptions v) noexcept
|
||||
{
|
||||
|
||||
@@ -180,7 +180,7 @@ template <int Bits>
|
||||
bool
|
||||
STBitString<Bits>::isDefault() const
|
||||
{
|
||||
return value_ == beast::kZERO;
|
||||
return value_ == beast::kZero;
|
||||
}
|
||||
|
||||
} // namespace xrpl
|
||||
|
||||
@@ -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 = kSF_GENERIC);
|
||||
STBlob(SerialIter&, SField const& name = kSfGeneric);
|
||||
|
||||
[[nodiscard]] std::size_t
|
||||
size() const;
|
||||
|
||||
@@ -7,11 +7,11 @@
|
||||
namespace xrpl {
|
||||
|
||||
/** Maximum JSON object nesting depth permitted during parsing. */
|
||||
inline constexpr std::size_t kMAX_PARSED_JSON_DEPTH = 64;
|
||||
inline constexpr std::size_t kMaxParsedJsonDepth = 64;
|
||||
|
||||
/** Maximum number of elements permitted in any JSON array field during parsing.
|
||||
Requests exceeding this limit are rejected with an invalidParams error. */
|
||||
inline constexpr std::size_t kMAX_PARSED_JSON_ARRAY_SIZE = 512;
|
||||
inline constexpr std::size_t kMaxParsedJsonArraySize = 512;
|
||||
|
||||
/** Holds the serialized result of parsing an input JSON object.
|
||||
This does validation and checking on the provided JSON.
|
||||
|
||||
@@ -30,8 +30,8 @@ class STTx final : public STObject, public CountedObject<STTx>
|
||||
TxType tx_type_;
|
||||
|
||||
public:
|
||||
static constexpr std::size_t kMIN_MULTI_SIGNERS = 1;
|
||||
static constexpr std::size_t kMAX_MULTI_SIGNERS = 32;
|
||||
static constexpr std::size_t kMinMultiSigners = 1;
|
||||
static constexpr std::size_t kMaxMultiSigners = 32;
|
||||
|
||||
STTx() = delete;
|
||||
STTx(STTx const& other) = default;
|
||||
|
||||
@@ -16,10 +16,10 @@ namespace xrpl {
|
||||
// Validation flags
|
||||
|
||||
// This is a full (as opposed to a partial) validation
|
||||
constexpr std::uint32_t kVF_FULL_VALIDATION = 0x00000001;
|
||||
constexpr std::uint32_t kVfFullValidation = 0x00000001;
|
||||
|
||||
// The signature is fully canonical
|
||||
constexpr std::uint32_t kVF_FULLY_CANONICAL_SIG = 0x80000000;
|
||||
constexpr std::uint32_t kVfFullyCanonicalSig = 0x80000000;
|
||||
|
||||
class STValidation final : public STObject, public CountedObject<STValidation>
|
||||
{
|
||||
@@ -204,7 +204,7 @@ STValidation::STValidation(
|
||||
f(*this);
|
||||
|
||||
// Finally, sign the validation and mark it as trusted:
|
||||
setFlag(kVF_FULLY_CANONICAL_SIG);
|
||||
setFlag(kVfFullyCanonicalSig);
|
||||
setFieldVL(sfSignature, signDigest(pk, sk, getSigningHash()));
|
||||
setTrusted();
|
||||
|
||||
|
||||
@@ -17,10 +17,10 @@ namespace xrpl {
|
||||
class SecretKey
|
||||
{
|
||||
public:
|
||||
static constexpr std::size_t kSIZE = 32;
|
||||
static constexpr std::size_t kSize = 32;
|
||||
|
||||
private:
|
||||
std::uint8_t buf_[kSIZE]{};
|
||||
std::uint8_t buf_[kSize]{};
|
||||
|
||||
public:
|
||||
using const_iterator = std::uint8_t const*;
|
||||
@@ -37,7 +37,7 @@ public:
|
||||
|
||||
~SecretKey();
|
||||
|
||||
SecretKey(std::array<std::uint8_t, kSIZE> const& data);
|
||||
SecretKey(std::array<std::uint8_t, kSize> const& data);
|
||||
SecretKey(Slice const& slice);
|
||||
|
||||
[[nodiscard]] std::uint8_t const*
|
||||
|
||||
@@ -134,13 +134,13 @@ public:
|
||||
bool
|
||||
getInteger(Integer& number, int offset)
|
||||
{
|
||||
static auto const kBYTES = sizeof(Integer);
|
||||
if ((offset + kBYTES) > data_.size())
|
||||
static auto const kBytes = sizeof(Integer);
|
||||
if ((offset + kBytes) > data_.size())
|
||||
return false;
|
||||
number = 0;
|
||||
|
||||
auto ptr = &data_[offset];
|
||||
for (auto i = 0; i < kBYTES; ++i)
|
||||
for (auto i = 0; i < kBytes; ++i)
|
||||
{
|
||||
if (i)
|
||||
number <<= 8;
|
||||
|
||||
@@ -14,22 +14,22 @@ namespace xrpl {
|
||||
static inline std::string const&
|
||||
systemName()
|
||||
{
|
||||
static std::string const kNAME = "xrpld";
|
||||
return kNAME;
|
||||
static std::string const kName = "xrpld";
|
||||
return kName;
|
||||
}
|
||||
|
||||
/** Configure the native currency. */
|
||||
|
||||
/** Number of drops in the genesis account. */
|
||||
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());
|
||||
constexpr XRPAmount kInitialXrp{100'000'000'000 * kDropsPerXrp};
|
||||
static_assert(kInitialXrp.drops() == 100'000'000'000'000'000);
|
||||
static_assert(Number::kMaxRep >= kInitialXrp.drops());
|
||||
|
||||
/** Returns true if the amount does not exceed the initial XRP in existence. */
|
||||
inline bool
|
||||
isLegalAmount(XRPAmount const& amount)
|
||||
{
|
||||
return amount <= kINITIAL_XRP;
|
||||
return amount <= kInitialXrp;
|
||||
}
|
||||
|
||||
/** 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 >= -kINITIAL_XRP && amount <= kINITIAL_XRP;
|
||||
return amount >= -kInitialXrp && amount <= kInitialXrp;
|
||||
}
|
||||
|
||||
/* The currency code for the native currency. */
|
||||
static inline std::string const&
|
||||
systemCurrencyCode()
|
||||
{
|
||||
static std::string const kCODE = "XRP";
|
||||
return kCODE;
|
||||
static std::string const kCode = "XRP";
|
||||
return kCode;
|
||||
}
|
||||
|
||||
/** The XRP ledger network's earliest allowed sequence */
|
||||
static constexpr std::uint32_t kXRP_LEDGER_EARLIEST_SEQ{32570u};
|
||||
static constexpr std::uint32_t kXrpLedgerEarliestSeq{32570u};
|
||||
|
||||
/** The XRP Ledger mainnet's earliest ledger with a FeeSettings object. Only
|
||||
* used in asserts and tests. */
|
||||
static constexpr std::uint32_t kXRP_LEDGER_EARLIEST_FEES{562177u};
|
||||
static constexpr std::uint32_t kXrpLedgerEarliestFees{562177u};
|
||||
|
||||
/** The minimum amount of support an amendment should have. */
|
||||
constexpr std::ratio<80, 100> kAMENDMENT_MAJORITY_CALC_THRESHOLD;
|
||||
constexpr std::ratio<80, 100> kAmendmentMajorityCalcThreshold;
|
||||
|
||||
/** The minimum amount of time an amendment must hold a majority */
|
||||
constexpr std::chrono::seconds const kDEFAULT_AMENDMENT_MAJORITY_TIME = weeks{2};
|
||||
constexpr std::chrono::seconds const kDefaultAmendmentMajorityTime = weeks{2};
|
||||
|
||||
} // namespace xrpl
|
||||
|
||||
/** Default peer port (IANA registered) */
|
||||
inline std::uint16_t constexpr kDEFAULT_PEER_PORT{2459};
|
||||
inline constexpr std::uint16_t kDefaultPeerPort{2459};
|
||||
|
||||
@@ -62,7 +62,7 @@ badCurrency();
|
||||
inline bool
|
||||
isXRP(Currency const& c)
|
||||
{
|
||||
return c == beast::kZERO;
|
||||
return c == beast::kZero;
|
||||
}
|
||||
|
||||
/** Returns "", "XRP", or three letter ISO code. */
|
||||
|
||||
@@ -300,13 +300,13 @@ public:
|
||||
using jsontype =
|
||||
std::conditional_t<std::is_signed_v<value_type>, json::Int, json::UInt>;
|
||||
|
||||
constexpr auto kMIN = std::numeric_limits<jsontype>::min();
|
||||
constexpr auto kMAX = std::numeric_limits<jsontype>::max();
|
||||
constexpr auto kMin = std::numeric_limits<jsontype>::min();
|
||||
constexpr auto kMax = std::numeric_limits<jsontype>::max();
|
||||
|
||||
if (value_ < kMIN)
|
||||
return kMIN;
|
||||
if (value_ > kMAX)
|
||||
return kMAX;
|
||||
if (value_ < kMin)
|
||||
return kMin;
|
||||
if (value_ > kMax)
|
||||
return kMax;
|
||||
return static_cast<jsontype>(value_);
|
||||
}
|
||||
else
|
||||
@@ -392,14 +392,14 @@ mulDivU(Source1 value, Dest mul, Source2 div)
|
||||
}
|
||||
|
||||
using desttype = typename Dest::value_type;
|
||||
constexpr auto kMAX = std::numeric_limits<desttype>::max();
|
||||
constexpr auto kMax = std::numeric_limits<desttype>::max();
|
||||
|
||||
// Shortcuts, since these happen a lot in the real world
|
||||
if (value == div)
|
||||
return mul;
|
||||
if (mul.value() == div.value())
|
||||
{
|
||||
if (value.value() > kMAX)
|
||||
if (value.value() > kMax)
|
||||
return std::nullopt;
|
||||
return Dest{static_cast<desttype>(value.value())};
|
||||
}
|
||||
@@ -414,7 +414,7 @@ mulDivU(Source1 value, Dest mul, Source2 div)
|
||||
|
||||
auto quotient = product / div.value();
|
||||
|
||||
if (quotient > kMAX)
|
||||
if (quotient > kMax)
|
||||
return std::nullopt;
|
||||
|
||||
return Dest{static_cast<desttype>(quotient)};
|
||||
|
||||
@@ -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 kMAX_ATTESTATIONS = 256;
|
||||
static constexpr std::uint32_t kMaxAttestations = 256;
|
||||
AttCollection attestations_;
|
||||
|
||||
protected:
|
||||
|
||||
@@ -202,13 +202,13 @@ public:
|
||||
std::is_signed_v<value_type> && std::is_integral_v<value_type>,
|
||||
"Expected XRPAmount to be a signed integral type");
|
||||
|
||||
constexpr auto kMIN = std::numeric_limits<json::Int>::min();
|
||||
constexpr auto kMAX = std::numeric_limits<json::Int>::max();
|
||||
constexpr auto kMin = std::numeric_limits<json::Int>::min();
|
||||
constexpr auto kMax = std::numeric_limits<json::Int>::max();
|
||||
|
||||
if (drops_ < kMIN)
|
||||
return kMIN;
|
||||
if (drops_ > kMAX)
|
||||
return kMAX;
|
||||
if (drops_ < kMin)
|
||||
return kMin;
|
||||
if (drops_ > kMax)
|
||||
return kMax;
|
||||
return static_cast<json::Int>(drops_);
|
||||
}
|
||||
|
||||
@@ -237,12 +237,12 @@ public:
|
||||
};
|
||||
|
||||
/** Number of drops per 1 XRP */
|
||||
constexpr XRPAmount kDROPS_PER_XRP{1'000'000};
|
||||
constexpr XRPAmount kDropsPerXrp{1'000'000};
|
||||
|
||||
constexpr double
|
||||
XRPAmount::decimalXRP() const
|
||||
{
|
||||
return static_cast<double>(drops_) / kDROPS_PER_XRP.drops();
|
||||
return static_cast<double>(drops_) / kDropsPerXrp.drops();
|
||||
}
|
||||
|
||||
// Output XRPAmount as just the drops value.
|
||||
|
||||
@@ -35,9 +35,9 @@ class STVar
|
||||
{
|
||||
private:
|
||||
// The largest "small object" we can accommodate
|
||||
static std::size_t constexpr kMAX_SIZE = 72;
|
||||
static constexpr std::size_t kMaxSize = 72;
|
||||
|
||||
std::aligned_storage<kMAX_SIZE>::type d_ = {};
|
||||
std::aligned_storage<kMaxSize>::type d_ = {};
|
||||
STBase* p_ = nullptr;
|
||||
|
||||
public:
|
||||
@@ -51,12 +51,12 @@ public:
|
||||
|
||||
STVar(STBase&& t) // NOLINT(cppcoreguidelines-rvalue-reference-param-not-moved)
|
||||
{
|
||||
p_ = t.move(kMAX_SIZE, &d_);
|
||||
p_ = t.move(kMaxSize, &d_);
|
||||
}
|
||||
|
||||
STVar(STBase const& t)
|
||||
{
|
||||
p_ = t.copy(kMAX_SIZE, &d_);
|
||||
p_ = t.copy(kMaxSize, &d_);
|
||||
}
|
||||
|
||||
STVar(DefaultObjectT, SField const& name);
|
||||
@@ -110,7 +110,7 @@ private:
|
||||
void
|
||||
construct(Args&&... args)
|
||||
{
|
||||
if constexpr (sizeof(T) > kMAX_SIZE)
|
||||
if constexpr (sizeof(T) > kMaxSize)
|
||||
{
|
||||
p_ = new T(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
@@ -155,16 +155,16 @@ inplaceBigintDivRem(std::span<uint64_t> numerator, std::uint64_t divisor)
|
||||
[[nodiscard]] inline std::array<std::uint8_t, 10>
|
||||
b5810ToB58Be(std::uint64_t input)
|
||||
{
|
||||
[[maybe_unused]] static constexpr std::uint64_t kB_58_10 = 430804206899405824; // 58^10;
|
||||
XRPL_ASSERT(input < kB_58_10, "xrpl::b58_fast::detail::b5810ToB58Be : valid input");
|
||||
constexpr std::size_t kRESULT_SIZE = 10;
|
||||
std::array<std::uint8_t, kRESULT_SIZE> result{};
|
||||
[[maybe_unused]] static constexpr std::uint64_t kB5810 = 430804206899405824; // 58^10;
|
||||
XRPL_ASSERT(input < kB5810, "xrpl::b58_fast::detail::b5810ToB58Be : valid input");
|
||||
static constexpr std::size_t kResultSize = 10;
|
||||
std::array<std::uint8_t, kResultSize> result{};
|
||||
int i = 0;
|
||||
while (input > 0)
|
||||
{
|
||||
std::uint64_t rem = 0;
|
||||
std::tie(input, rem) = divRem(input, 58);
|
||||
result[kRESULT_SIZE - 1 - i] = rem;
|
||||
result[kResultSize - 1 - i] = rem;
|
||||
i += 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -84,7 +84,7 @@ LEDGER_ENTRY(ltNEGATIVE_UNL, 0x004e, NegativeUNL, nunl, ({
|
||||
|
||||
/** A ledger object which contains a list of NFTs
|
||||
|
||||
\sa keylet::nftpage_min, keylet::nftpage_max, keylet::nftpage
|
||||
\sa keylet::nftpageMin, keylet::nftpageMax, keylet::nftpage
|
||||
*/
|
||||
LEDGER_ENTRY(ltNFTOKEN_PAGE, 0x0050, NFTokenPage, nft_page, ({
|
||||
{sfPreviousPageMin, SoeOptional},
|
||||
@@ -112,7 +112,7 @@ LEDGER_ENTRY(ltSIGNER_LIST, 0x0053, SignerList, signer_list, ({
|
||||
|
||||
/** A ledger object which describes a ticket.
|
||||
|
||||
\sa keylet::ticket
|
||||
\sa keylet::kTICKET
|
||||
*/
|
||||
LEDGER_ENTRY(ltTICKET, 0x0054, Ticket, ticket, ({
|
||||
{sfAccount, SoeRequired},
|
||||
|
||||
@@ -27,7 +27,7 @@ TYPED_SFIELD(sfWasLockingChainSend, UINT8, 19)
|
||||
TYPED_SFIELD(sfWithdrawalPolicy, UINT8, 20)
|
||||
|
||||
// 16-bit integers (common)
|
||||
TYPED_SFIELD(sfLedgerEntryType, UINT16, 1, SField::kSMD_NEVER)
|
||||
TYPED_SFIELD(sfLedgerEntryType, UINT16, 1, SField::kSmdNever)
|
||||
TYPED_SFIELD(sfTransactionType, UINT16, 2)
|
||||
TYPED_SFIELD(sfSignerWeight, UINT16, 3)
|
||||
TYPED_SFIELD(sfTransferFee, UINT16, 4)
|
||||
@@ -48,7 +48,7 @@ TYPED_SFIELD(sfNetworkID, UINT32, 1)
|
||||
TYPED_SFIELD(sfFlags, UINT32, 2)
|
||||
TYPED_SFIELD(sfSourceTag, UINT32, 3)
|
||||
TYPED_SFIELD(sfSequence, UINT32, 4)
|
||||
TYPED_SFIELD(sfPreviousTxnLgrSeq, UINT32, 5, SField::kSMD_DELETE_FINAL)
|
||||
TYPED_SFIELD(sfPreviousTxnLgrSeq, UINT32, 5, SField::kSmdDeleteFinal)
|
||||
TYPED_SFIELD(sfLedgerSequence, UINT32, 6)
|
||||
TYPED_SFIELD(sfCloseTime, UINT32, 7)
|
||||
TYPED_SFIELD(sfParentCloseTime, UINT32, 8)
|
||||
@@ -138,12 +138,12 @@ TYPED_SFIELD(sfXChainClaimID, UINT64, 20)
|
||||
TYPED_SFIELD(sfXChainAccountCreateCount, UINT64, 21)
|
||||
TYPED_SFIELD(sfXChainAccountClaimCount, UINT64, 22)
|
||||
TYPED_SFIELD(sfAssetPrice, UINT64, 23)
|
||||
TYPED_SFIELD(sfMaximumAmount, UINT64, 24, SField::kSMD_BASE_TEN|SField::kSMD_DEFAULT)
|
||||
TYPED_SFIELD(sfOutstandingAmount, UINT64, 25, SField::kSMD_BASE_TEN|SField::kSMD_DEFAULT)
|
||||
TYPED_SFIELD(sfMPTAmount, UINT64, 26, SField::kSMD_BASE_TEN|SField::kSMD_DEFAULT)
|
||||
TYPED_SFIELD(sfMaximumAmount, UINT64, 24, SField::kSmdBaseTen|SField::kSmdDefault)
|
||||
TYPED_SFIELD(sfOutstandingAmount, UINT64, 25, SField::kSmdBaseTen|SField::kSmdDefault)
|
||||
TYPED_SFIELD(sfMPTAmount, UINT64, 26, SField::kSmdBaseTen|SField::kSmdDefault)
|
||||
TYPED_SFIELD(sfIssuerNode, UINT64, 27)
|
||||
TYPED_SFIELD(sfSubjectNode, UINT64, 28)
|
||||
TYPED_SFIELD(sfLockedAmount, UINT64, 29, SField::kSMD_BASE_TEN|SField::kSMD_DEFAULT)
|
||||
TYPED_SFIELD(sfLockedAmount, UINT64, 29, SField::kSmdBaseTen|SField::kSmdDefault)
|
||||
TYPED_SFIELD(sfVaultNode, UINT64, 30)
|
||||
TYPED_SFIELD(sfLoanBrokerNode, UINT64, 31)
|
||||
|
||||
@@ -167,17 +167,17 @@ TYPED_SFIELD(sfLedgerHash, UINT256, 1)
|
||||
TYPED_SFIELD(sfParentHash, UINT256, 2)
|
||||
TYPED_SFIELD(sfTransactionHash, UINT256, 3)
|
||||
TYPED_SFIELD(sfAccountHash, UINT256, 4)
|
||||
TYPED_SFIELD(sfPreviousTxnID, UINT256, 5, SField::kSMD_DELETE_FINAL)
|
||||
TYPED_SFIELD(sfPreviousTxnID, UINT256, 5, SField::kSmdDeleteFinal)
|
||||
TYPED_SFIELD(sfLedgerIndex, UINT256, 6)
|
||||
TYPED_SFIELD(sfWalletLocator, UINT256, 7)
|
||||
TYPED_SFIELD(sfRootIndex, UINT256, 8, SField::kSMD_ALWAYS)
|
||||
TYPED_SFIELD(sfRootIndex, UINT256, 8, SField::kSmdAlways)
|
||||
TYPED_SFIELD(sfAccountTxnID, UINT256, 9)
|
||||
TYPED_SFIELD(sfNFTokenID, UINT256, 10)
|
||||
TYPED_SFIELD(sfEmitParentTxnID, UINT256, 11)
|
||||
TYPED_SFIELD(sfEmitNonce, UINT256, 12)
|
||||
TYPED_SFIELD(sfEmitHookHash, UINT256, 13)
|
||||
TYPED_SFIELD(sfAMMID, UINT256, 14,
|
||||
SField::kSMD_PSEUDO_ACCOUNT | SField::kSMD_DEFAULT)
|
||||
SField::kSmdPseudoAccount | SField::kSmdDefault)
|
||||
|
||||
// 256-bit (uncommon)
|
||||
TYPED_SFIELD(sfBookDirectory, UINT256, 16)
|
||||
@@ -200,30 +200,30 @@ TYPED_SFIELD(sfHookNamespace, UINT256, 32)
|
||||
TYPED_SFIELD(sfHookSetTxnID, UINT256, 33)
|
||||
TYPED_SFIELD(sfDomainID, UINT256, 34)
|
||||
TYPED_SFIELD(sfVaultID, UINT256, 35,
|
||||
SField::kSMD_PSEUDO_ACCOUNT | SField::kSMD_DEFAULT)
|
||||
SField::kSmdPseudoAccount | SField::kSmdDefault)
|
||||
TYPED_SFIELD(sfParentBatchID, UINT256, 36)
|
||||
TYPED_SFIELD(sfLoanBrokerID, UINT256, 37,
|
||||
SField::kSMD_PSEUDO_ACCOUNT | SField::kSMD_DEFAULT)
|
||||
SField::kSmdPseudoAccount | SField::kSmdDefault)
|
||||
TYPED_SFIELD(sfLoanID, UINT256, 38)
|
||||
|
||||
// number (common)
|
||||
TYPED_SFIELD(sfNumber, NUMBER, 1)
|
||||
TYPED_SFIELD(sfAssetsAvailable, NUMBER, 2, SField::kSMD_NEEDS_ASSET | SField::kSMD_DEFAULT)
|
||||
TYPED_SFIELD(sfAssetsMaximum, NUMBER, 3, SField::kSMD_NEEDS_ASSET | SField::kSMD_DEFAULT)
|
||||
TYPED_SFIELD(sfAssetsTotal, NUMBER, 4, SField::kSMD_NEEDS_ASSET | SField::kSMD_DEFAULT)
|
||||
TYPED_SFIELD(sfLossUnrealized, NUMBER, 5, SField::kSMD_NEEDS_ASSET | SField::kSMD_DEFAULT)
|
||||
TYPED_SFIELD(sfDebtTotal, NUMBER, 6, SField::kSMD_NEEDS_ASSET | SField::kSMD_DEFAULT)
|
||||
TYPED_SFIELD(sfDebtMaximum, NUMBER, 7, SField::kSMD_NEEDS_ASSET | SField::kSMD_DEFAULT)
|
||||
TYPED_SFIELD(sfCoverAvailable, NUMBER, 8, SField::kSMD_NEEDS_ASSET | SField::kSMD_DEFAULT)
|
||||
TYPED_SFIELD(sfAssetsAvailable, NUMBER, 2, SField::kSmdNeedsAsset | SField::kSmdDefault)
|
||||
TYPED_SFIELD(sfAssetsMaximum, NUMBER, 3, SField::kSmdNeedsAsset | SField::kSmdDefault)
|
||||
TYPED_SFIELD(sfAssetsTotal, NUMBER, 4, SField::kSmdNeedsAsset | SField::kSmdDefault)
|
||||
TYPED_SFIELD(sfLossUnrealized, NUMBER, 5, SField::kSmdNeedsAsset | SField::kSmdDefault)
|
||||
TYPED_SFIELD(sfDebtTotal, NUMBER, 6, SField::kSmdNeedsAsset | SField::kSmdDefault)
|
||||
TYPED_SFIELD(sfDebtMaximum, NUMBER, 7, SField::kSmdNeedsAsset | SField::kSmdDefault)
|
||||
TYPED_SFIELD(sfCoverAvailable, NUMBER, 8, SField::kSmdNeedsAsset | SField::kSmdDefault)
|
||||
TYPED_SFIELD(sfLoanOriginationFee, NUMBER, 9)
|
||||
TYPED_SFIELD(sfLoanServiceFee, NUMBER, 10)
|
||||
TYPED_SFIELD(sfLatePaymentFee, NUMBER, 11)
|
||||
TYPED_SFIELD(sfClosePaymentFee, NUMBER, 12)
|
||||
TYPED_SFIELD(sfPrincipalOutstanding, NUMBER, 13, SField::kSMD_NEEDS_ASSET | SField::kSMD_DEFAULT)
|
||||
TYPED_SFIELD(sfPrincipalOutstanding, NUMBER, 13, SField::kSmdNeedsAsset | SField::kSmdDefault)
|
||||
TYPED_SFIELD(sfPrincipalRequested, NUMBER, 14)
|
||||
TYPED_SFIELD(sfTotalValueOutstanding, NUMBER, 15, SField::kSMD_NEEDS_ASSET | SField::kSMD_DEFAULT)
|
||||
TYPED_SFIELD(sfTotalValueOutstanding, NUMBER, 15, SField::kSmdNeedsAsset | SField::kSmdDefault)
|
||||
TYPED_SFIELD(sfPeriodicPayment, NUMBER, 16)
|
||||
TYPED_SFIELD(sfManagementFeeOutstanding, NUMBER, 17, SField::kSMD_NEEDS_ASSET | SField::kSMD_DEFAULT)
|
||||
TYPED_SFIELD(sfManagementFeeOutstanding, NUMBER, 17, SField::kSmdNeedsAsset | SField::kSmdDefault)
|
||||
|
||||
// int32
|
||||
TYPED_SFIELD(sfLoanScale, INT32, 1)
|
||||
@@ -269,9 +269,9 @@ TYPED_SFIELD(sfLPTokenBalance, AMOUNT, 31)
|
||||
TYPED_SFIELD(sfPublicKey, VL, 1)
|
||||
TYPED_SFIELD(sfMessageKey, VL, 2)
|
||||
TYPED_SFIELD(sfSigningPubKey, VL, 3)
|
||||
TYPED_SFIELD(sfTxnSignature, VL, 4, SField::kSMD_DEFAULT, SField::kNOT_SIGNING)
|
||||
TYPED_SFIELD(sfTxnSignature, VL, 4, SField::kSmdDefault, SField::kNotSigning)
|
||||
TYPED_SFIELD(sfURI, VL, 5)
|
||||
TYPED_SFIELD(sfSignature, VL, 6, SField::kSMD_DEFAULT, SField::kNOT_SIGNING)
|
||||
TYPED_SFIELD(sfSignature, VL, 6, SField::kSmdDefault, SField::kNotSigning)
|
||||
TYPED_SFIELD(sfDomain, VL, 7)
|
||||
TYPED_SFIELD(sfFundCode, VL, 8)
|
||||
TYPED_SFIELD(sfRemoveCode, VL, 9)
|
||||
@@ -284,7 +284,7 @@ TYPED_SFIELD(sfMemoFormat, VL, 14)
|
||||
// variable length (uncommon)
|
||||
TYPED_SFIELD(sfFulfillment, VL, 16)
|
||||
TYPED_SFIELD(sfCondition, VL, 17)
|
||||
TYPED_SFIELD(sfMasterSignature, VL, 18, SField::kSMD_DEFAULT, SField::kNOT_SIGNING)
|
||||
TYPED_SFIELD(sfMasterSignature, VL, 18, SField::kSmdDefault, SField::kNotSigning)
|
||||
TYPED_SFIELD(sfUNLModifyValidator, VL, 19)
|
||||
TYPED_SFIELD(sfValidatorToDisable, VL, 20)
|
||||
TYPED_SFIELD(sfValidatorToReEnable, VL, 21)
|
||||
@@ -326,7 +326,7 @@ TYPED_SFIELD(sfBorrower, ACCOUNT, 25)
|
||||
TYPED_SFIELD(sfCounterparty, ACCOUNT, 26)
|
||||
|
||||
// vector of 256-bit
|
||||
TYPED_SFIELD(sfIndexes, VECTOR256, 1, SField::kSMD_NEVER)
|
||||
TYPED_SFIELD(sfIndexes, VECTOR256, 1, SField::kSmdNever)
|
||||
TYPED_SFIELD(sfHashes, VECTOR256, 2)
|
||||
TYPED_SFIELD(sfAmendments, VECTOR256, 3)
|
||||
TYPED_SFIELD(sfNFTokenOffers, VECTOR256, 4)
|
||||
@@ -387,13 +387,13 @@ UNTYPED_SFIELD(sfCredential, OBJECT, 33)
|
||||
UNTYPED_SFIELD(sfRawTransaction, OBJECT, 34)
|
||||
UNTYPED_SFIELD(sfBatchSigner, OBJECT, 35)
|
||||
UNTYPED_SFIELD(sfBook, OBJECT, 36)
|
||||
UNTYPED_SFIELD(sfCounterpartySignature, OBJECT, 37, SField::kSMD_DEFAULT, SField::kNOT_SIGNING)
|
||||
UNTYPED_SFIELD(sfCounterpartySignature, OBJECT, 37, SField::kSmdDefault, SField::kNotSigning)
|
||||
|
||||
// array of objects (common)
|
||||
// ARRAY/1 is reserved for end of array
|
||||
// sfSigningAccounts has never been used.
|
||||
//UNTYPED_SFIELD(sfSigningAccounts, ARRAY, 2)
|
||||
UNTYPED_SFIELD(sfSigners, ARRAY, 3, SField::kSMD_DEFAULT, SField::kNOT_SIGNING)
|
||||
UNTYPED_SFIELD(sfSigners, ARRAY, 3, SField::kSmdDefault, SField::kNotSigning)
|
||||
UNTYPED_SFIELD(sfSignerEntries, ARRAY, 4)
|
||||
UNTYPED_SFIELD(sfTemplate, ARRAY, 5)
|
||||
UNTYPED_SFIELD(sfNecessary, ARRAY, 6)
|
||||
@@ -421,4 +421,4 @@ UNTYPED_SFIELD(sfUnauthorizeCredentials, ARRAY, 27)
|
||||
UNTYPED_SFIELD(sfAcceptedCredentials, ARRAY, 28)
|
||||
UNTYPED_SFIELD(sfPermissions, ARRAY, 29)
|
||||
UNTYPED_SFIELD(sfRawTransactions, ARRAY, 30)
|
||||
UNTYPED_SFIELD(sfBatchSigners, ARRAY, 31, SField::kSMD_DEFAULT, SField::kNOT_SIGNING)
|
||||
UNTYPED_SFIELD(sfBatchSigners, ARRAY, 31, SField::kSmdDefault, SField::kNotSigning)
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace xrpl {
|
||||
struct OpensslRipemd160Hasher
|
||||
{
|
||||
public:
|
||||
static constexpr auto const kENDIAN = boost::endian::order::native;
|
||||
static constexpr auto kEndian = boost::endian::order::native;
|
||||
|
||||
using result_type = std::array<std::uint8_t, 20>;
|
||||
|
||||
@@ -50,7 +50,7 @@ private:
|
||||
struct OpensslSha512Hasher
|
||||
{
|
||||
public:
|
||||
static constexpr auto const kENDIAN = boost::endian::order::native;
|
||||
static constexpr auto kEndian = boost::endian::order::native;
|
||||
|
||||
using result_type = std::array<std::uint8_t, 64>;
|
||||
|
||||
@@ -73,7 +73,7 @@ private:
|
||||
struct OpensslSha256Hasher
|
||||
{
|
||||
public:
|
||||
static constexpr auto const kENDIAN = boost::endian::order::native;
|
||||
static constexpr auto kEndian = boost::endian::order::native;
|
||||
|
||||
using result_type = std::array<std::uint8_t, 32>;
|
||||
|
||||
@@ -118,7 +118,7 @@ private:
|
||||
sha256_hasher h_;
|
||||
|
||||
public:
|
||||
static constexpr auto const kENDIAN = boost::endian::order::native;
|
||||
static constexpr auto kEndian = boost::endian::order::native;
|
||||
|
||||
using result_type = std::array<std::uint8_t, 20>;
|
||||
|
||||
@@ -154,7 +154,7 @@ private:
|
||||
sha512_hasher h_;
|
||||
|
||||
public:
|
||||
static constexpr auto const kENDIAN = boost::endian::order::big;
|
||||
static constexpr auto kEndian = boost::endian::order::big;
|
||||
|
||||
using result_type = uint256;
|
||||
|
||||
|
||||
@@ -29,11 +29,11 @@ toUInt32(Taxon t)
|
||||
return static_cast<std::uint32_t>(t);
|
||||
}
|
||||
|
||||
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;
|
||||
constexpr std::uint16_t const kFlagBurnable = 0x0001;
|
||||
constexpr std::uint16_t const kFlagOnlyXrp = 0x0002;
|
||||
constexpr std::uint16_t const kFlagCreateTrustLines = 0x0004;
|
||||
constexpr std::uint16_t const kFlagTransferable = 0x0008;
|
||||
constexpr std::uint16_t const kFlagMutable = 0x0010;
|
||||
|
||||
inline std::uint16_t
|
||||
getFlags(uint256 const& id)
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace xrpl::nft {
|
||||
|
||||
// NFT directory pages order their contents based only on the low 96 bits of
|
||||
// the NFToken value. This mask provides easy access to the necessary mask.
|
||||
uint256 constexpr kPAGE_MASK(
|
||||
constexpr uint256 kPageMask(
|
||||
std::string_view("0000000000000000000000000000000000000000ffffffffffffffffffffffff"));
|
||||
|
||||
} // namespace xrpl::nft
|
||||
|
||||
@@ -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* 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;"};
|
||||
inline constexpr char const* kCommonDbPragmaJournal{"PRAGMA journal_mode=%s;"};
|
||||
inline constexpr char const* kCommonDbPragmaSync{"PRAGMA synchronous=%s;"};
|
||||
inline constexpr char const* kCommonDbPragmaTemp{"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 kSQLITE_TUNING_CUTOFF = 10'000'000;
|
||||
inline constexpr std::uint32_t kSqliteTuningCutoff = 10'000'000;
|
||||
|
||||
// Ledger database holds ledgers and ledger confirmations
|
||||
inline constexpr auto kLGR_DB_NAME{"ledger.db"};
|
||||
inline constexpr auto kLgrDbName{"ledger.db"};
|
||||
|
||||
inline constexpr std::array<char const*, 5> kLGR_DB_INIT{
|
||||
inline constexpr std::array<char const*, 5> kLgrDbInit{
|
||||
{"BEGIN TRANSACTION;",
|
||||
|
||||
"CREATE TABLE IF NOT EXISTS Ledgers ( \
|
||||
@@ -47,9 +47,9 @@ inline constexpr std::array<char const*, 5> kLGR_DB_INIT{
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Transaction database holds transactions and public keys
|
||||
inline constexpr auto kTX_DB_NAME{"transaction.db"};
|
||||
inline constexpr auto kTxDbName{"transaction.db"};
|
||||
|
||||
inline constexpr std::array<char const*, 8> kTX_DB_INIT{
|
||||
inline constexpr std::array<char const*, 8> kTxDbInit{
|
||||
{"BEGIN TRANSACTION;",
|
||||
|
||||
"CREATE TABLE IF NOT EXISTS Transactions ( \
|
||||
@@ -82,9 +82,9 @@ inline constexpr std::array<char const*, 8> kTX_DB_INIT{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline constexpr auto kWALLET_DB_NAME{"wallet.db"};
|
||||
inline constexpr auto kWalletDbName{"wallet.db"};
|
||||
|
||||
inline constexpr std::array<char const*, 6> kWALLET_DB_INIT{
|
||||
inline constexpr std::array<char const*, 6> kWalletDbInit{
|
||||
{"BEGIN TRANSACTION;",
|
||||
|
||||
// A node's identity must be persisted, including
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user