Skip to content

Commit 3ca1593

Browse files
committed
Partially implement Lending Protocol (#5270)
- Spec: XLS-66 - Introduces amendment "featureLendingProtocol", but leaves it UNSUPPORTED to allow for future development work. - AccountInfo RPC will indicate the type of pseudo-account when appropriate. - Refactors and improves several existing classes and functional areas, including Number, STAmount, STObject, json_value, Asset, directory handling, View helper functions, and unit test helpers.
1 parent c9f17dd commit 3ca1593

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+18785
-528
lines changed

include/xrpl/basics/Number.h

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@ class Number;
1313
std::string
1414
to_string(Number const& amount);
1515

16+
template <typename T>
17+
constexpr bool
18+
isPowerOfTen(T value)
19+
{
20+
while (value >= 10 && value % 10 == 0)
21+
value /= 10;
22+
return value == 1;
23+
}
24+
1625
class Number
1726
{
1827
using rep = std::int64_t;
@@ -22,7 +31,9 @@ class Number
2231
public:
2332
// The range for the mantissa when normalized
2433
constexpr static std::int64_t minMantissa = 1'000'000'000'000'000LL;
25-
constexpr static std::int64_t maxMantissa = 9'999'999'999'999'999LL;
34+
static_assert(isPowerOfTen(minMantissa));
35+
constexpr static std::int64_t maxMantissa = minMantissa * 10 - 1;
36+
static_assert(maxMantissa == 9'999'999'999'999'999LL);
2637

2738
// The range for the exponent when normalized
2839
constexpr static int minExponent = -32768;
@@ -132,22 +143,7 @@ class Number
132143
}
133144

134145
Number
135-
truncate() const noexcept
136-
{
137-
if (exponent_ >= 0 || mantissa_ == 0)
138-
return *this;
139-
140-
Number ret = *this;
141-
while (ret.exponent_ < 0 && ret.mantissa_ != 0)
142-
{
143-
ret.exponent_ += 1;
144-
ret.mantissa_ /= rep(10);
145-
}
146-
// We are guaranteed that normalize() will never throw an exception
147-
// because exponent is either negative or zero at this point.
148-
ret.normalize();
149-
return ret;
150-
}
146+
truncate() const noexcept;
151147

152148
friend constexpr bool
153149
operator>(Number const& x, Number const& y) noexcept
@@ -192,6 +188,8 @@ class Number
192188
class Guard;
193189
};
194190

191+
constexpr static Number numZero{};
192+
195193
inline constexpr Number::Number(rep mantissa, int exponent, unchecked) noexcept
196194
: mantissa_{mantissa}, exponent_{exponent}
197195
{

include/xrpl/beast/utility/instrumentation.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// The duplication is because Visual Studio 2019 cannot compile that header
1414
// even with the option -Zc:__cplusplus added.
1515
#define ALWAYS(cond, message, ...) assert((message) && (cond))
16-
#define ALWAYS_OR_UNREACHABLE(cond, message, ...) assert((message) && (cond))
16+
#define ALWAYS_OR_UNREACHABLE(cond, message) assert((message) && (cond))
1717
#define SOMETIMES(cond, message, ...)
1818
#define REACHABLE(message, ...)
1919
#define UNREACHABLE(message, ...) assert((message) && false)

include/xrpl/json/json_value.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,9 @@ class Value
381381
/// Return true if the object has a member named key.
382382
bool
383383
isMember(std::string const& key) const;
384+
/// Return true if the object has a member named key.
385+
bool
386+
isMember(StaticString const& key) const;
384387

385388
/// \brief Return a list of the member names.
386389
///

include/xrpl/ledger/ApplyView.h

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,45 @@ class ApplyView : public ReadView
368368
emptyDirDelete(Keylet const& directory);
369369
};
370370

371+
namespace directory {
372+
/** Helper functions for managing low-level directory operations.
373+
These are not part of the ApplyView interface.
374+
375+
Don't use them unless you really, really know what you're doing.
376+
Instead use dirAdd, dirInsert, etc.
377+
*/
378+
379+
std::uint64_t
380+
createRoot(
381+
ApplyView& view,
382+
Keylet const& directory,
383+
uint256 const& key,
384+
std::function<void(std::shared_ptr<SLE> const&)> const& describe);
385+
386+
auto
387+
findPreviousPage(ApplyView& view, Keylet const& directory, SLE::ref start);
388+
389+
std::uint64_t
390+
insertKey(
391+
ApplyView& view,
392+
SLE::ref node,
393+
std::uint64_t page,
394+
bool preserveOrder,
395+
STVector256& indexes,
396+
uint256 const& key);
397+
398+
std::optional<std::uint64_t>
399+
insertPage(
400+
ApplyView& view,
401+
std::uint64_t page,
402+
SLE::pointer node,
403+
std::uint64_t nextPage,
404+
SLE::ref next,
405+
uint256 const& key,
406+
Keylet const& directory,
407+
std::function<void(std::shared_ptr<SLE> const&)> const& describe);
408+
409+
} // namespace directory
371410
} // namespace ripple
372411

373412
#endif

0 commit comments

Comments
 (0)