Skip to content

Commit c6a50de

Browse files
committed
Implement Lending Protocol (unsupported) (#5270)
- Spec: XLS-66 - Introduces amendment "LendingProtocol", but leaves it UNSUPPORTED to allow for standalone testing, future development work, and potential bug fixes. - 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 b195011 commit c6a50de

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

+18784
-526
lines changed

include/xrpl/basics/Number.h

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@ class Number;
3232
std::string
3333
to_string(Number const& amount);
3434

35+
template <typename T>
36+
constexpr bool
37+
isPowerOfTen(T value)
38+
{
39+
while (value >= 10 && value % 10 == 0)
40+
value /= 10;
41+
return value == 1;
42+
}
43+
3544
class Number
3645
{
3746
using rep = std::int64_t;
@@ -41,7 +50,9 @@ class Number
4150
public:
4251
// The range for the mantissa when normalized
4352
constexpr static std::int64_t minMantissa = 1'000'000'000'000'000LL;
44-
constexpr static std::int64_t maxMantissa = 9'999'999'999'999'999LL;
53+
static_assert(isPowerOfTen(minMantissa));
54+
constexpr static std::int64_t maxMantissa = minMantissa * 10 - 1;
55+
static_assert(maxMantissa == 9'999'999'999'999'999LL);
4556

4657
// The range for the exponent when normalized
4758
constexpr static int minExponent = -32768;
@@ -151,22 +162,7 @@ class Number
151162
}
152163

153164
Number
154-
truncate() const noexcept
155-
{
156-
if (exponent_ >= 0 || mantissa_ == 0)
157-
return *this;
158-
159-
Number ret = *this;
160-
while (ret.exponent_ < 0 && ret.mantissa_ != 0)
161-
{
162-
ret.exponent_ += 1;
163-
ret.mantissa_ /= rep(10);
164-
}
165-
// We are guaranteed that normalize() will never throw an exception
166-
// because exponent is either negative or zero at this point.
167-
ret.normalize();
168-
return ret;
169-
}
165+
truncate() const noexcept;
170166

171167
friend constexpr bool
172168
operator>(Number const& x, Number const& y) noexcept
@@ -211,6 +207,8 @@ class Number
211207
class Guard;
212208
};
213209

210+
constexpr static Number numZero{};
211+
214212
inline constexpr Number::Number(rep mantissa, int exponent, unchecked) noexcept
215213
: mantissa_{mantissa}, exponent_{exponent}
216214
{

include/xrpl/beast/utility/instrumentation.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
3232
// The duplication is because Visual Studio 2019 cannot compile that header
3333
// even with the option -Zc:__cplusplus added.
3434
#define ALWAYS(cond, message, ...) assert((message) && (cond))
35-
#define ALWAYS_OR_UNREACHABLE(cond, message, ...) assert((message) && (cond))
35+
#define ALWAYS_OR_UNREACHABLE(cond, message) assert((message) && (cond))
3636
#define SOMETIMES(cond, message, ...)
3737
#define REACHABLE(message, ...)
3838
#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
@@ -400,6 +400,9 @@ class Value
400400
/// Return true if the object has a member named key.
401401
bool
402402
isMember(std::string const& key) const;
403+
/// Return true if the object has a member named key.
404+
bool
405+
isMember(StaticString const& key) const;
403406

404407
/// \brief Return a list of the member names.
405408
///

include/xrpl/ledger/ApplyView.h

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,45 @@ class ApplyView : public ReadView
387387
emptyDirDelete(Keylet const& directory);
388388
};
389389

390+
namespace directory {
391+
/** Helper functions for managing low-level directory operations.
392+
These are not part of the ApplyView interface.
393+
394+
Don't use them unless you really, really know what you're doing.
395+
Instead use dirAdd, dirInsert, etc.
396+
*/
397+
398+
std::uint64_t
399+
createRoot(
400+
ApplyView& view,
401+
Keylet const& directory,
402+
uint256 const& key,
403+
std::function<void(std::shared_ptr<SLE> const&)> const& describe);
404+
405+
auto
406+
findPreviousPage(ApplyView& view, Keylet const& directory, SLE::ref start);
407+
408+
std::uint64_t
409+
insertKey(
410+
ApplyView& view,
411+
SLE::ref node,
412+
std::uint64_t page,
413+
bool preserveOrder,
414+
STVector256& indexes,
415+
uint256 const& key);
416+
417+
std::optional<std::uint64_t>
418+
insertPage(
419+
ApplyView& view,
420+
std::uint64_t page,
421+
SLE::pointer node,
422+
std::uint64_t nextPage,
423+
SLE::ref next,
424+
uint256 const& key,
425+
Keylet const& directory,
426+
std::function<void(std::shared_ptr<SLE> const&)> const& describe);
427+
428+
} // namespace directory
390429
} // namespace ripple
391430

392431
#endif

0 commit comments

Comments
 (0)