diff --git a/src/test/jtx/TestHelpers.h b/src/test/jtx/TestHelpers.h index 534419494d..c18de93623 100644 --- a/src/test/jtx/TestHelpers.h +++ b/src/test/jtx/TestHelpers.h @@ -35,6 +35,82 @@ namespace ripple { namespace test { namespace jtx { +/** Generic helper class for helper clases that set a field on a JTx. + + Not every helper will be able to use this because of conversions and other + issues, but for classes where it's straightforward, this can simplify things. +*/ +template +struct field +{ +protected: + F const& field_; + V value_; + +public: + explicit field(F const& field, V const& value) + : field_(field), value_(value) + { + } + + virtual JV + value() const = 0; + + virtual void + operator()(Env&, JTx& jt) const + { + jt.jv[field_.jsonName] = value(); + } +}; + +template +struct field +{ +protected: + F const& field_; + V value_; + +public: + explicit field(F const& field, V const& value) + : field_(field), value_(value) + { + } + + virtual void + operator()(Env&, JTx& jt) const + { + jt.jv[field_.jsonName] = value_; + } +}; + +template +using simpleField = field; + +struct timePointField + : public field +{ + using F = SF_UINT32; + using V = NetClock::time_point; + using JV = NetClock::rep; + using base = field; + +protected: + using base::value_; + +public: + + explicit timePointField(F const& field, V const& value) + : field(field, value) + { + } + + JV + value() const override + { + return value_.time_since_epoch().count(); + } +}; + // TODO We only need this long "requires" clause as polyfill, for C++20 // implementations which are missing header. Replace with // `std::ranges::range`, and accordingly use std::ranges::begin/end @@ -264,48 +340,25 @@ std::array constexpr cb1 = { std::array const fb1 = {{0xA0, 0x02, 0x80, 0x00}}; /** Set the "FinishAfter" time tag on a JTx */ -struct finish_time +struct finish_time : public timePointField { -private: - NetClock::time_point value_; - -public: - explicit finish_time(NetClock::time_point const& value) : value_(value) + explicit finish_time(NetClock::time_point const& value) + : timePointField(sfFinishAfter, value) { } - - void - operator()(Env&, JTx& jt) const - { - jt.jv[sfFinishAfter.jsonName] = value_.time_since_epoch().count(); - } }; /** Set the "CancelAfter" time tag on a JTx */ -struct cancel_time +struct cancel_time : public timePointField { -private: - NetClock::time_point value_; - -public: - explicit cancel_time(NetClock::time_point const& value) : value_(value) + explicit cancel_time(NetClock::time_point const& value) : timePointField(sfCancelAfter, value) { } - - void - operator()(jtx::Env&, jtx::JTx& jt) const - { - jt.jv[sfCancelAfter.jsonName] = value_.time_since_epoch().count(); - } }; -struct condition +struct condition: public simpleField { -private: - std::string value_; - -public: - explicit condition(Slice const& cond) : value_(strHex(cond)) + explicit condition(Slice const& cond) : field(sfCondition, strHex(cond)) { } @@ -314,12 +367,6 @@ public: : condition(makeSlice(c)) { } - - void - operator()(Env&, JTx& jt) const - { - jt.jv[sfCondition.jsonName] = value_; - } }; struct fulfillment @@ -461,6 +508,24 @@ create( } // namespace check +/* LoanBroker */ +/******************************************************************************/ + +namespace loanBroker { + +Json::Value +create(AccountID const& account, uint256 const& vaultId); + +/* +inline Json::Value +create(Account const& account, uint256 const& vaultId) +{ + return create(account.id(), vaultId); +} +*/ + +} // namespace loanBroker + } // namespace jtx } // namespace test } // namespace ripple diff --git a/src/xrpld/app/tx/detail/LoanBrokerSet.cpp b/src/xrpld/app/tx/detail/LoanBrokerSet.cpp index a92c863f5c..fb7fe3875b 100644 --- a/src/xrpld/app/tx/detail/LoanBrokerSet.cpp +++ b/src/xrpld/app/tx/detail/LoanBrokerSet.cpp @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ /* This file is part of rippled: https://github.com/ripple/rippled - Copyright (c) 2022 Ripple Labs Inc. + Copyright (c) 2025 Ripple Labs Inc. Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above diff --git a/src/xrpld/app/tx/detail/LoanBrokerSet.h b/src/xrpld/app/tx/detail/LoanBrokerSet.h index b8f08ce684..be118ebe92 100644 --- a/src/xrpld/app/tx/detail/LoanBrokerSet.h +++ b/src/xrpld/app/tx/detail/LoanBrokerSet.h @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ /* This file is part of rippled: https://github.com/ripple/rippled - Copyright (c) 2022 Ripple Labs Inc. + Copyright (c) 2025 Ripple Labs Inc. Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above