diff --git a/include/xrpl/protocol/SField.h b/include/xrpl/protocol/SField.h index 4dedea748b6..4c88423054d 100644 --- a/include/xrpl/protocol/SField.h +++ b/include/xrpl/protocol/SField.h @@ -68,6 +68,7 @@ class STCurrency; STYPE(STI_UINT128, 4) \ STYPE(STI_UINT256, 5) \ STYPE(STI_AMOUNT, 6) \ + STYPE(STI_EITHER_AMOUNT, 6) \ STYPE(STI_VL, 7) \ STYPE(STI_ACCOUNT, 8) \ \ @@ -301,8 +302,17 @@ class SField static std::map knownCodeToField; }; +enum class SFieldMPT { None, Yes, No }; + +// clang-format off +template +concept ValidFields = (std::is_same_v && + (F == SFieldMPT::No || F == SFieldMPT::Yes)) || + (!std::is_same_v && F == SFieldMPT::None); + /** A field with a type known at compile time. */ -template +template + requires ValidFields struct TypedField : SField { using type = T; @@ -312,22 +322,25 @@ struct TypedField : SField }; /** Indicate std::optional field semantics. */ -template +template + requires ValidFields struct OptionaledField { - TypedField const* f; + TypedField const* f; - explicit OptionaledField(TypedField const& f_) : f(&f_) + explicit OptionaledField(TypedField const& f_) : f(&f_) { } }; -template -inline OptionaledField -operator~(TypedField const& f) +template + requires ValidFields +inline OptionaledField +operator~(TypedField const& f) { - return OptionaledField(f); + return OptionaledField(f); } +// clang-format on //------------------------------------------------------------------------------ @@ -346,7 +359,8 @@ using SF_UINT384 = TypedField>; using SF_UINT512 = TypedField>; using SF_ACCOUNT = TypedField; -using SF_AMOUNT = TypedField; +using SF_AMOUNT = TypedField; +using SF_EITHER_AMOUNT = TypedField; using SF_ISSUE = TypedField; using SF_CURRENCY = TypedField; using SF_VL = TypedField; @@ -520,7 +534,7 @@ extern SF_UINT256 const sfHookNamespace; extern SF_UINT256 const sfHookSetTxnID; // currency amount (common) -extern SF_AMOUNT const sfAmount; +extern SF_EITHER_AMOUNT const sfAmount; extern SF_AMOUNT const sfBalance; extern SF_AMOUNT const sfLimitAmount; extern SF_AMOUNT const sfTakerPays; @@ -528,8 +542,8 @@ extern SF_AMOUNT const sfTakerGets; extern SF_AMOUNT const sfLowLimit; extern SF_AMOUNT const sfHighLimit; extern SF_AMOUNT const sfFee; -extern SF_AMOUNT const sfSendMax; -extern SF_AMOUNT const sfDeliverMin; +extern SF_EITHER_AMOUNT const sfSendMax; +extern SF_EITHER_AMOUNT const sfDeliverMin; extern SF_AMOUNT const sfAmount2; extern SF_AMOUNT const sfEPrice; extern SF_AMOUNT const sfBidMin; diff --git a/include/xrpl/protocol/SOTemplate.h b/include/xrpl/protocol/SOTemplate.h index 95f11f37658..2ea726c6e29 100644 --- a/include/xrpl/protocol/SOTemplate.h +++ b/include/xrpl/protocol/SOTemplate.h @@ -40,7 +40,8 @@ enum SOEStyle { // constructed with STObject::makeInnerObject() }; -enum SOESupportMPT : bool { soeMPTYes = true, soeMPTNo = false }; +/** Amount fields that can support MPT */ +enum SOETxMPTAmount { soeMPTNone, soeMPTSupported, soeMPTNotSupported }; //------------------------------------------------------------------------------ @@ -50,7 +51,7 @@ class SOElement // Use std::reference_wrapper so SOElement can be stored in a std::vector. std::reference_wrapper sField_; SOEStyle style_; - SOESupportMPT supportMpt_; + SOETxMPTAmount supportMpt_; private: void @@ -70,14 +71,14 @@ class SOElement SOElement(SField const& fieldName, SOEStyle style) : sField_(fieldName) , style_(style) - , supportMpt_(SOESupportMPT::soeMPTNo) + , supportMpt_(SOETxMPTAmount::soeMPTNone) { init(fieldName); } SOElement( - TypedField const& fieldName, + TypedField const& fieldName, SOEStyle style, - SOESupportMPT supportMpt = SOESupportMPT::soeMPTNo) + SOETxMPTAmount supportMpt = SOETxMPTAmount::soeMPTNotSupported) : sField_(fieldName), style_(style), supportMpt_(supportMpt) { init(fieldName); @@ -95,10 +96,10 @@ class SOElement return style_; } - SOESupportMPT + bool supportMPT() const { - return supportMpt_; + return supportMpt_ == SOETxMPTAmount::soeMPTSupported; } }; diff --git a/include/xrpl/protocol/STEitherAmount.h b/include/xrpl/protocol/STEitherAmount.h index a3ab1c4b2bc..3c62b42986c 100644 --- a/include/xrpl/protocol/STEitherAmount.h +++ b/include/xrpl/protocol/STEitherAmount.h @@ -49,7 +49,8 @@ class STEitherAmount : public STBase, public CountedObject STEitherAmount(SerialIter& sit, SField const& name); STEitherAmount(XRPAmount const& amount); STEitherAmount(STAmount const& amount); - STEitherAmount(SField const& name, STAmount const& amount); + STEitherAmount(SField const& name, STAmount const& amount = STAmount{}); + STEitherAmount(SField const& name, STMPTAmount const& amount); STEitherAmount(STMPTAmount const& amount); STEitherAmount& @@ -102,15 +103,6 @@ class STEitherAmount : public STBase, public CountedObject AccountID const& getIssuer() const; - bool - badAsset() const; - - bool - sameAsset(STEitherAmount const& amount) const; - - bool - sameIssue(STEitherAmount const& amount) const; - bool negative() const; @@ -192,6 +184,9 @@ get(auto&& amount) STEitherAmount amountFromJson(SField const& name, Json::Value const& v); +STAmount +amountFromJson(SF_AMOUNT const& name, Json::Value const& v); + bool amountFromJsonNoThrow(STEitherAmount& result, Json::Value const& jvSource); diff --git a/include/xrpl/protocol/STObject.h b/include/xrpl/protocol/STObject.h index 8a6a651463e..2a08447a91b 100644 --- a/include/xrpl/protocol/STObject.h +++ b/include/xrpl/protocol/STObject.h @@ -55,11 +55,11 @@ throwFieldNotFound(SField const& field) class STObject : public STBase, public CountedObject { // Proxy value for a STBase derived class - template + template class Proxy; - template + template class ValueProxy; - template + template class OptionalProxy; struct Transform @@ -238,6 +238,9 @@ class STObject : public STBase, public CountedObject getFieldVL(SField const& field) const; STEitherAmount const& getFieldAmount(SField const& field) const; + STAmount const& + getFieldAmount( + TypedField const& field) const; STPathSet const& getFieldPathSet(SField const& field) const; const STVector256& @@ -254,9 +257,14 @@ class STObject : public STBase, public CountedObject @return The value of the specified field. @throws STObject::FieldErr if the field is not present. */ - template + template typename T::value_type - operator[](TypedField const& f) const; + operator[](TypedField const& f) const; + + /** Overload for amount fields that don't support MPT + */ + STAmount + operator[](TypedField const& f) const; /** Get the value of a field as a std::optional @@ -266,9 +274,14 @@ class STObject : public STBase, public CountedObject @return std::nullopt if the field is not present, else the value of the specified field. */ - template + template std::optional> - operator[](OptionaledField const& of) const; + operator[](OptionaledField const& of) const; + + /** Overload for amount fields that don't support MPT + */ + std::optional + operator[](OptionaledField const& of) const; /** Get a modifiable field value. @param A TypedField built from an SField value representing the desired @@ -277,9 +290,14 @@ class STObject : public STBase, public CountedObject @return A modifiable reference to the value of the specified field. @throws STObject::FieldErr if the field is not present. */ - template - ValueProxy - operator[](TypedField const& f); + template + ValueProxy + operator[](TypedField const& f); + + /** Overload for amount fields that don't support MPT + */ + ValueProxy + operator[](TypedField const& f); /** Return a modifiable field value as std::optional @@ -290,9 +308,14 @@ class STObject : public STBase, public CountedObject reference to the value of the specified field. Returns std::nullopt if the field is not present. */ - template - OptionalProxy - operator[](OptionaledField const& of); + template + OptionalProxy + operator[](OptionaledField const& of); + + /** Overload for amount fields that don't support MPT + */ + OptionalProxy + operator[](OptionaledField const& of); /** Get the value of a field. @param A TypedField built from an SField value representing the desired @@ -301,9 +324,14 @@ class STObject : public STBase, public CountedObject @return The value of the specified field. @throws STObject::FieldErr if the field is not present. */ - template + template typename T::value_type - at(TypedField const& f) const; + at(TypedField const& f) const; + + /** Overload for amount fields that don't support MPT + */ + STAmount + at(TypedField const& f) const; /** Get the value of a field as std::optional @@ -313,9 +341,14 @@ class STObject : public STBase, public CountedObject @return std::nullopt if the field is not present, else the value of the specified field. */ - template + template std::optional> - at(OptionaledField const& of) const; + at(OptionaledField const& of) const; + + /** Overload for amount fields that don't support MPT + */ + std::optional + at(OptionaledField const& of) const; /** Get a modifiable field value. @param A TypedField built from an SField value representing the desired @@ -324,9 +357,14 @@ class STObject : public STBase, public CountedObject @return A modifiable reference to the value of the specified field. @throws STObject::FieldErr if the field is not present. */ - template - ValueProxy - at(TypedField const& f); + template + ValueProxy + at(TypedField const& f); + + /** Overload for amount fields that don't support MPT + */ + ValueProxy + at(TypedField const& f); /** Return a modifiable field value as std::optional @@ -337,9 +375,14 @@ class STObject : public STBase, public CountedObject reference to the value of the specified field. Returns std::nullopt if the field is not present. */ - template - OptionalProxy - at(OptionaledField const& of); + template + OptionalProxy + at(OptionaledField const& of); + + /** Overload for amount fields that don't support MPT + */ + OptionalProxy + at(OptionaledField const& of); /** Set a field. if the field already exists, it is replaced. @@ -430,6 +473,14 @@ class STObject : public STBase, public CountedObject static std::vector getSortedFields(STObject const& objToSort, WhichFields whichFields); + template + typename T::value_type + atImpl(TypedField const& f) const; + + template + std::optional> + atImpl(OptionaledField const& of) const; + // Implementation for getting (most) fields that return by value. // // The remove_cv and remove_reference are necessitated by the STBitString @@ -476,19 +527,19 @@ class STObject : public STBase, public CountedObject //------------------------------------------------------------------------------ -template +template class STObject::Proxy { protected: - using value_type = typename T::value_type; + using value_type = VT; STObject* st_; SOEStyle style_; - TypedField const* f_; + TypedField const* f_; Proxy(Proxy const&) = default; - Proxy(STObject* st, TypedField const* f); + Proxy(STObject* st, TypedField const* f); value_type value() const; @@ -501,11 +552,11 @@ class STObject::Proxy assign(U&& u); }; -template -class STObject::ValueProxy : private Proxy +template +class STObject::ValueProxy : private Proxy { private: - using value_type = typename T::value_type; + using value_type = VT; public: ValueProxy(ValueProxy const&) = default; @@ -521,14 +572,14 @@ class STObject::ValueProxy : private Proxy private: friend class STObject; - ValueProxy(STObject* st, TypedField const* f); + ValueProxy(STObject* st, TypedField const* f); }; -template -class STObject::OptionalProxy : private Proxy +template +class STObject::OptionalProxy : private Proxy { private: - using value_type = typename T::value_type; + using value_type = VT; using optional_type = std::optional::type>; @@ -643,7 +694,7 @@ class STObject::OptionalProxy : private Proxy private: friend class STObject; - OptionalProxy(STObject* st, TypedField const* f); + OptionalProxy(STObject* st, TypedField const* f); bool engaged() const noexcept; @@ -660,8 +711,9 @@ class STObject::FieldErr : public std::runtime_error using std::runtime_error::runtime_error; }; -template -STObject::Proxy::Proxy(STObject* st, TypedField const* f) : st_(st), f_(f) +template +STObject::Proxy::Proxy(STObject* st, TypedField const* f) + : st_(st), f_(f) { if (st_->mType) { @@ -677,9 +729,9 @@ STObject::Proxy::Proxy(STObject* st, TypedField const* f) : st_(st), f_(f) } } -template +template auto -STObject::Proxy::value() const -> value_type +STObject::Proxy::value() const -> value_type { auto const t = find(); if (t) @@ -696,17 +748,37 @@ STObject::Proxy::value() const -> value_type return value_type{}; } -template +template <> +inline auto +STObject::Proxy::value() const + -> STAmount +{ + auto const t = find(); + if (t) + return get(t->value()); + if (style_ == soeINVALID) + { + Throw("Value requested from invalid STObject."); + } + if (style_ != soeDEFAULT) + { + Throw( + "Missing field '" + this->f_->getName() + "'"); + } + return STAmount{}; +} + +template inline T const* -STObject::Proxy::find() const +STObject::Proxy::find() const { return dynamic_cast(st_->peekAtPField(*f_)); } -template +template template void -STObject::Proxy::assign(U&& u) +STObject::Proxy::assign(U&& u) { if (style_ == soeDEFAULT && u == value_type{}) { @@ -724,67 +796,71 @@ STObject::Proxy::assign(U&& u) //------------------------------------------------------------------------------ -template +template template -std::enable_if_t, STObject::ValueProxy&> -STObject::ValueProxy::operator=(U&& u) +std::enable_if_t, STObject::ValueProxy&> +STObject::ValueProxy::operator=(U&& u) { this->assign(std::forward(u)); return *this; } -template -STObject::ValueProxy::operator value_type() const +template +STObject::ValueProxy::operator value_type() const { return this->value(); } -template -STObject::ValueProxy::ValueProxy(STObject* st, TypedField const* f) - : Proxy(st, f) +template +STObject::ValueProxy::ValueProxy( + STObject* st, + TypedField const* f) + : Proxy(st, f) { } //------------------------------------------------------------------------------ -template -STObject::OptionalProxy::operator bool() const noexcept +template +STObject::OptionalProxy::operator bool() const noexcept { return engaged(); } -template +template auto -STObject::OptionalProxy::operator*() const -> value_type +STObject::OptionalProxy::operator*() const -> value_type { return this->value(); } -template -STObject::OptionalProxy::operator typename STObject::OptionalProxy< - T>::optional_type() const +template +STObject::OptionalProxy::operator typename STObject:: + OptionalProxy::optional_type() const { return optional_value(); } -template -typename STObject::OptionalProxy::optional_type -STObject::OptionalProxy::operator~() const +template +typename STObject::OptionalProxy::optional_type +STObject::OptionalProxy::operator~() const { return optional_value(); } -template +template auto -STObject::OptionalProxy::operator=(std::nullopt_t const&) -> OptionalProxy& +STObject::OptionalProxy::operator=(std::nullopt_t const&) + -> OptionalProxy& { disengage(); return *this; } -template +template auto -STObject::OptionalProxy::operator=(optional_type&& v) -> OptionalProxy& +STObject::OptionalProxy::operator=(optional_type&& v) + -> OptionalProxy& { if (v) this->assign(std::move(*v)); @@ -793,9 +869,10 @@ STObject::OptionalProxy::operator=(optional_type&& v) -> OptionalProxy& return *this; } -template +template auto -STObject::OptionalProxy::operator=(optional_type const& v) -> OptionalProxy& +STObject::OptionalProxy::operator=(optional_type const& v) + -> OptionalProxy& { if (v) this->assign(*v); @@ -804,31 +881,33 @@ STObject::OptionalProxy::operator=(optional_type const& v) -> OptionalProxy& return *this; } -template +template template -std::enable_if_t, STObject::OptionalProxy&> -STObject::OptionalProxy::operator=(U&& u) +std::enable_if_t, STObject::OptionalProxy&> +STObject::OptionalProxy::operator=(U&& u) { this->assign(std::forward(u)); return *this; } -template -STObject::OptionalProxy::OptionalProxy(STObject* st, TypedField const* f) - : Proxy(st, f) +template +STObject::OptionalProxy::OptionalProxy( + STObject* st, + TypedField const* f) + : Proxy(st, f) { } -template +template bool -STObject::OptionalProxy::engaged() const noexcept +STObject::OptionalProxy::engaged() const noexcept { return this->style_ == soeDEFAULT || this->find() != nullptr; } -template +template void -STObject::OptionalProxy::disengage() +STObject::OptionalProxy::disengage() { if (this->style_ == soeREQUIRED || this->style_ == soeDEFAULT) Throw( @@ -839,18 +918,18 @@ STObject::OptionalProxy::disengage() this->st_->makeFieldAbsent(*this->f_); } -template +template auto -STObject::OptionalProxy::optional_value() const -> optional_type +STObject::OptionalProxy::optional_value() const -> optional_type { if (!engaged()) return std::nullopt; return this->value(); } -template -typename STObject::OptionalProxy::value_type -STObject::OptionalProxy::value_or(value_type val) const +template +typename STObject::OptionalProxy::value_type +STObject::OptionalProxy::value_or(value_type val) const { return engaged() ? this->value() : val; } @@ -955,37 +1034,64 @@ STObject::getPIndex(int offset) return &v_[offset].get(); } -template +template typename T::value_type -STObject::operator[](TypedField const& f) const +STObject::operator[](TypedField const& f) const +{ + return at(f); +} + +inline STAmount +STObject::operator[](TypedField const& f) const { return at(f); } -template +template std::optional> -STObject::operator[](OptionaledField const& of) const +STObject::operator[](OptionaledField const& of) const { return at(of); } -template +inline std::optional +STObject::operator[]( + OptionaledField const& of) const +{ + return at(of); +} + +template inline auto -STObject::operator[](TypedField const& f) -> ValueProxy +STObject::operator[](TypedField const& f) -> ValueProxy { return at(f); } -template inline auto -STObject::operator[](OptionaledField const& of) -> OptionalProxy +STObject::operator[](TypedField const& f) + -> ValueProxy +{ + return at(f); +} + +template +inline auto +STObject::operator[](OptionaledField const& of) -> OptionalProxy { return at(of); } -template +inline auto +STObject::operator[](OptionaledField const& of) + -> OptionalProxy +{ + return at(of); +} + +template typename T::value_type -STObject::at(TypedField const& f) const +STObject::atImpl(TypedField const& f) const { auto const b = peekAtPField(f); if (!b) @@ -1010,9 +1116,22 @@ STObject::at(TypedField const& f) const return dv; } -template +template +typename T::value_type +STObject::at(TypedField const& f) const +{ + return atImpl(f); +} + +inline STAmount +STObject::at(TypedField const& f) const +{ + return get(atImpl(f)); +} + +template std::optional> -STObject::at(OptionaledField const& of) const +STObject::atImpl(OptionaledField const& of) const { auto const b = peekAtPField(*of.f); if (!b) @@ -1030,18 +1149,45 @@ STObject::at(OptionaledField const& of) const return u->value(); } -template +template +std::optional> +STObject::at(OptionaledField const& of) const +{ + return atImpl(of); +} + +inline std::optional +STObject::at(OptionaledField const& of) const +{ + return get(atImpl(of)); +} + +template +inline auto +STObject::at(TypedField const& f) -> ValueProxy +{ + return ValueProxy(this, &f); +} + +inline auto +STObject::at(TypedField const& f) + -> ValueProxy +{ + return ValueProxy(this, &f); +} + +template inline auto -STObject::at(TypedField const& f) -> ValueProxy +STObject::at(OptionaledField const& of) -> OptionalProxy { - return ValueProxy(this, &f); + return OptionalProxy(this, of.f); } -template inline auto -STObject::at(OptionaledField const& of) -> OptionalProxy +STObject::at(OptionaledField const& of) + -> OptionalProxy { - return OptionalProxy(this, of.f); + return OptionalProxy(this, of.f); } template diff --git a/src/libxrpl/protocol/SField.cpp b/src/libxrpl/protocol/SField.cpp index 2d7615c85c8..731d3c050da 100644 --- a/src/libxrpl/protocol/SField.cpp +++ b/src/libxrpl/protocol/SField.cpp @@ -38,12 +38,15 @@ struct SField::private_access_tag_t static SField::private_access_tag_t access; -template +// clang-format off +template + requires ValidFields template -TypedField::TypedField(private_access_tag_t pat, Args&&... args) +TypedField::TypedField(private_access_tag_t pat, Args&&... args) : SField(pat, std::forward(args)...) { } +// clang-format on // Construct all compile-time SFields, and register them in the knownCodeToField // database: @@ -247,7 +250,7 @@ CONSTRUCT_TYPED_SFIELD(sfHookNamespace, "HookNamespace", UINT256, CONSTRUCT_TYPED_SFIELD(sfHookSetTxnID, "HookSetTxnID", UINT256, 33); // currency amount (common) -CONSTRUCT_TYPED_SFIELD(sfAmount, "Amount", AMOUNT, 1); +CONSTRUCT_TYPED_SFIELD(sfAmount, "Amount", EITHER_AMOUNT, 1); CONSTRUCT_TYPED_SFIELD(sfBalance, "Balance", AMOUNT, 2); CONSTRUCT_TYPED_SFIELD(sfLimitAmount, "LimitAmount", AMOUNT, 3); CONSTRUCT_TYPED_SFIELD(sfTakerPays, "TakerPays", AMOUNT, 4); @@ -255,8 +258,8 @@ CONSTRUCT_TYPED_SFIELD(sfTakerGets, "TakerGets", AMOUNT, CONSTRUCT_TYPED_SFIELD(sfLowLimit, "LowLimit", AMOUNT, 6); CONSTRUCT_TYPED_SFIELD(sfHighLimit, "HighLimit", AMOUNT, 7); CONSTRUCT_TYPED_SFIELD(sfFee, "Fee", AMOUNT, 8); -CONSTRUCT_TYPED_SFIELD(sfSendMax, "SendMax", AMOUNT, 9); -CONSTRUCT_TYPED_SFIELD(sfDeliverMin, "DeliverMin", AMOUNT, 10); +CONSTRUCT_TYPED_SFIELD(sfSendMax, "SendMax", EITHER_AMOUNT, 9); +CONSTRUCT_TYPED_SFIELD(sfDeliverMin, "DeliverMin", EITHER_AMOUNT, 10); CONSTRUCT_TYPED_SFIELD(sfAmount2, "Amount2", AMOUNT, 11); CONSTRUCT_TYPED_SFIELD(sfBidMin, "BidMin", AMOUNT, 12); CONSTRUCT_TYPED_SFIELD(sfBidMax, "BidMax", AMOUNT, 13); diff --git a/src/libxrpl/protocol/STEitherAmount.cpp b/src/libxrpl/protocol/STEitherAmount.cpp index dd18665d816..cde7bc30d29 100644 --- a/src/libxrpl/protocol/STEitherAmount.cpp +++ b/src/libxrpl/protocol/STEitherAmount.cpp @@ -51,6 +51,11 @@ STEitherAmount::STEitherAmount(SField const& name, STAmount const& amount) { } +STEitherAmount::STEitherAmount(SField const& name, STMPTAmount const& amount) + : STBase(name), amount_{amount} +{ +} + STEitherAmount::STEitherAmount(STMPTAmount const& amount) : STBase(amount.getFName()), amount_{amount} { @@ -59,7 +64,6 @@ STEitherAmount::STEitherAmount(STMPTAmount const& amount) STEitherAmount& STEitherAmount::operator=(STAmount const& amount) { - setFName(amount.getFName()); amount_ = amount; return *this; } @@ -67,7 +71,6 @@ STEitherAmount::operator=(STAmount const& amount) STEitherAmount& STEitherAmount::operator=(STMPTAmount const& amount) { - setFName(amount.getFName()); amount_ = amount; return *this; } @@ -144,14 +147,6 @@ STEitherAmount::isIssue() const return std::holds_alternative(amount_); } -bool -STEitherAmount::badAsset() const -{ - if (isIssue()) - return badCurrency() == std::get(amount_).getCurrency(); - return badMPT() == std::get(amount_).getCurrency(); -} - bool STEitherAmount::negative() const { @@ -175,34 +170,6 @@ STEitherAmount::zeroed() const [&](auto&& a) { return STEitherAmount{a.zeroed()}; }, amount_); } -bool -STEitherAmount::sameAsset(STEitherAmount const& amount) const -{ - return std::visit( - [&](T1&& a1, T2&& a2) { - if constexpr (std::is_same_v) - return a1.getCurrency() == a2.getCurrency(); - else - return false; - }, - amount_, - amount.amount_); -} - -bool -STEitherAmount::sameIssue(STEitherAmount const& amount) const -{ - return std::visit( - [&](T1&& a1, T2&& a2) { - if constexpr (std::is_same_v) - return a1.issue() == a2.issue(); - else - return false; - }, - amount_, - amount.amount_); -} - STEitherAmount const& STEitherAmount::value() const { @@ -255,7 +222,9 @@ validJSONIssue(Json::Value const& jv) jv.isMember(jss::mpt_issuance_id)); } -STEitherAmount +namespace detail { + +static STEitherAmount amountFromJson(SField const& name, Json::Value const& v) { STAmount::mantissa_type mantissa = 0; @@ -394,14 +363,42 @@ amountFromJson(SField const& name, Json::Value const& v) } if (std::holds_alternative(issue)) - return STAmount{ - name, std::get(issue), mantissa, exponent, native, negative}; + return STEitherAmount{ + name, + STAmount{ + name, + std::get(issue), + mantissa, + exponent, + native, + negative}}; while (exponent-- > 0) mantissa *= 10; - if (mantissa > 0x8000000000000000) + if (mantissa > STMPTAmount::cMaxMPTValue) Throw("MPT amount out of range"); - return STMPTAmount{ - name, std::get(issue), static_cast(mantissa)}; + return STEitherAmount{ + name, + STMPTAmount{ + name, + std::get(issue), + static_cast(mantissa)}}; +} + +} // namespace detail + +STEitherAmount +amountFromJson(SField const& name, Json::Value const& v) +{ + return detail::amountFromJson(name, v); +} + +STAmount +amountFromJson(SF_AMOUNT const& name, Json::Value const& v) +{ + auto res = detail::amountFromJson(name, v); + if (!res.isIssue()) + Throw("Amount is not STAmount"); + return get(res); } bool diff --git a/src/libxrpl/protocol/STObject.cpp b/src/libxrpl/protocol/STObject.cpp index 2984799277d..299811d093f 100644 --- a/src/libxrpl/protocol/STObject.cpp +++ b/src/libxrpl/protocol/STObject.cpp @@ -645,6 +645,14 @@ STObject::getFieldAmount(SField const& field) const return getFieldByConstRef(field, empty); } +STAmount const& +STObject::getFieldAmount( + TypedField const& field) const +{ + static STEitherAmount const empty{}; + return get(getFieldByConstRef(field, empty)); +} + STPathSet const& STObject::getFieldPathSet(SField const& field) const { diff --git a/src/libxrpl/protocol/TxFormats.cpp b/src/libxrpl/protocol/TxFormats.cpp index 3f76ccd6903..7d0067ae10e 100644 --- a/src/libxrpl/protocol/TxFormats.cpp +++ b/src/libxrpl/protocol/TxFormats.cpp @@ -162,12 +162,12 @@ TxFormats::TxFormats() ttPAYMENT, { {sfDestination, soeREQUIRED}, - {sfAmount, soeREQUIRED, soeMPTYes}, - {sfSendMax, soeOPTIONAL}, + {sfAmount, soeREQUIRED, soeMPTSupported}, + {sfSendMax, soeOPTIONAL, soeMPTSupported}, {sfPaths, soeDEFAULT}, {sfInvoiceID, soeOPTIONAL}, {sfDestinationTag, soeOPTIONAL}, - {sfDeliverMin, soeOPTIONAL}, + {sfDeliverMin, soeOPTIONAL, soeMPTSupported}, }, commonFields); @@ -377,7 +377,7 @@ TxFormats::TxFormats() add(jss::Clawback, ttCLAWBACK, { - {sfAmount, soeREQUIRED, soeMPTYes}, + {sfAmount, soeREQUIRED, soeMPTSupported}, {sfMPTokenHolder, soeOPTIONAL}, }, commonFields); diff --git a/src/libxrpl/protocol/XChainAttestations.cpp b/src/libxrpl/protocol/XChainAttestations.cpp index 10a5aaf0549..d72075e02c7 100644 --- a/src/libxrpl/protocol/XChainAttestations.cpp +++ b/src/libxrpl/protocol/XChainAttestations.cpp @@ -276,7 +276,7 @@ AttestationCreateAccount::AttestationCreateAccount(STObject const& o) : AttestationBase(o) , createCount{o[sfXChainAccountCreateCount]} , toCreate{o[sfDestination]} - , rewardAmount{get(o[sfSignatureReward])} + , rewardAmount{o[sfSignatureReward]} { } @@ -352,7 +352,7 @@ AttestationCreateAccount::toSTObject() const o[sfXChainAccountCreateCount] = createCount; o[sfDestination] = toCreate; - o[sfSignatureReward] = STEitherAmount{rewardAmount}; + o[sfSignatureReward] = rewardAmount; return o; } @@ -372,7 +372,7 @@ AttestationCreateAccount::message( // Serialize in SField order to make python serializers easier to write o[sfXChainAccountCreateCount] = createCount; o[sfAmount] = STEitherAmount{sendingAmount}; - o[sfSignatureReward] = STEitherAmount{rewardAmount}; + o[sfSignatureReward] = rewardAmount; o[sfDestination] = dst; o[sfOtherChainSource] = sendingAccount; o[sfAttestationRewardAccount] = rewardAccount; @@ -577,7 +577,7 @@ XChainCreateAccountAttestation::XChainCreateAccountAttestation( o[sfAttestationSignerAccount], PublicKey{o[sfPublicKey]}, get(o[sfAmount]), - get(o[sfSignatureReward]), + o[sfSignatureReward], o[sfAttestationRewardAccount], o[sfWasLockingChainSend] != 0, o[sfDestination]} {}; @@ -617,7 +617,7 @@ XChainCreateAccountAttestation::toSTObject() const STAccount{sfAttestationSignerAccount, keyAccount}; o[sfPublicKey] = publicKey; o[sfAmount] = STEitherAmount{sfAmount, amount}; - o[sfSignatureReward] = STEitherAmount{sfSignatureReward, rewardAmount}; + o[sfSignatureReward] = STAmount{sfSignatureReward, rewardAmount}; o[sfAttestationRewardAccount] = STAccount{sfAttestationRewardAccount, rewardAccount}; o[sfWasLockingChainSend] = wasLockingChainSend; diff --git a/src/test/app/Check_test.cpp b/src/test/app/Check_test.cpp index 0a899c82671..cb82bef9b59 100644 --- a/src/test/app/Check_test.cpp +++ b/src/test/app/Check_test.cpp @@ -2147,10 +2147,8 @@ class Check_test : public beast::unit_test::suite // without comparing the currency. auto cmpReqAmount = [this, offerLine, checkLine](SF_AMOUNT const& sfield) { - STAmount const offerAmount = - get(offerLine->at(sfield)); - STAmount const checkAmount = - get(checkLine->at(sfield)); + STAmount const offerAmount = offerLine->at(sfield); + STAmount const checkAmount = checkLine->at(sfield); // Neither STAmount should be native. if (!BEAST_EXPECT( diff --git a/src/test/app/Flow_test.cpp b/src/test/app/Flow_test.cpp index 250871747c4..ee11f5e4747 100644 --- a/src/test/app/Flow_test.cpp +++ b/src/test/app/Flow_test.cpp @@ -551,8 +551,7 @@ struct Flow_test : public beast::unit_test::suite return std::stoull(bookDirStr, nullptr, 16); }(); std::uint64_t const actualRate = getRate( - get(usdOffer->at(sfTakerGets)), - get(usdOffer->at(sfTakerPays))); + usdOffer->at(sfTakerGets), usdOffer->at(sfTakerPays)); // We expect the actual rate of the offer to be worse // (larger) than the rate of the book page holding the diff --git a/src/test/app/MPToken_test.cpp b/src/test/app/MPToken_test.cpp index 1000b255573..94cbe5a616b 100644 --- a/src/test/app/MPToken_test.cpp +++ b/src/test/app/MPToken_test.cpp @@ -847,6 +847,56 @@ class MPToken_test : public beast::unit_test::suite // bob can send back to alice(issuer) just fine mptAlice.pay(bob, alice, 10); } + + // MPT is disabled + { + Env env{*this, features - featureMPTokensV1}; + Account const alice("alice"); + Account const bob("bob"); + + env.fund(XRP(1'000), alice); + env.fund(XRP(1'000), bob); + STMPTAmount mpt{ + MPTIssue{std::make_pair(1, alice.id())}, UINT64_C(100)}; + + env(pay(alice, bob, mpt), ter(temDISABLED)); + } + + // Invalid combination of send, sendMax, deliverMin + { + Env env{*this, features}; + Account const alice("alice"); + Account const carol("carol"); + Account const bob("bob"); + + MPTTester mptAlice(env, alice, {.holders = {&bob, &carol}}); + + mptAlice.create({.ownerCount = 1, .holderCount = 0}); + + mptAlice.authorize({.account = &bob}); + + mptAlice.authorize({.account = &carol}); + + env(pay(alice, bob, mptAlice.mpt(100)), + sendmax(XRP(100)), + delivermin(XRP(100)), + ter(temMALFORMED)); + + env(pay(alice, bob, mptAlice.mpt(100)), + sendmax(mptAlice.mpt(100)), + delivermin(XRP(100)), + ter(temMALFORMED)); + + env(pay(alice, bob, XRP(100)), + sendmax(mptAlice.mpt(100)), + delivermin(XRP(100)), + ter(temMALFORMED)); + + env(pay(alice, bob, XRP(100)), + sendmax(XRP(100)), + delivermin(mptAlice.mpt(100)), + ter(temMALFORMED)); + } } void @@ -874,7 +924,8 @@ class MPToken_test : public beast::unit_test::suite Account const alice("alice"); env.fund(XRP(1'000), alice); - STMPTAmount mpt{MPTIssue{std::make_pair(1, alice.id())}, 100llu}; + STMPTAmount mpt{ + MPTIssue{std::make_pair(1, alice.id())}, UINT64_C(100)}; env(offer(alice, mpt, XRP(100)), ter(temMALFORMED)); env.close(); diff --git a/src/test/app/Offer_test.cpp b/src/test/app/Offer_test.cpp index 76019741c34..01608b5b805 100644 --- a/src/test/app/Offer_test.cpp +++ b/src/test/app/Offer_test.cpp @@ -2315,13 +2315,10 @@ class OfferBaseUtil_test : public beast::unit_test::suite low.setIssuer(accountLow ? account.id() : issue.account); high.setIssuer(accountLow ? issue.account : account.id()); - BEAST_EXPECT( - get(sleTrust->getFieldAmount(sfLowLimit)) == low); - BEAST_EXPECT( - get(sleTrust->getFieldAmount(sfHighLimit)) == high); + BEAST_EXPECT(sleTrust->getFieldAmount(sfLowLimit) == low); + BEAST_EXPECT(sleTrust->getFieldAmount(sfHighLimit) == high); - STAmount actualBalance{ - get(sleTrust->getFieldAmount(sfBalance))}; + STAmount actualBalance{sleTrust->getFieldAmount(sfBalance)}; if (!accountLow) actualBalance.negate(); @@ -2955,10 +2952,8 @@ class OfferBaseUtil_test : public beast::unit_test::suite auto const& acctOffer = *(acctOffers.front()); BEAST_EXPECT(acctOffer[sfLedgerEntryType] == ltOFFER); - BEAST_EXPECT( - get(acctOffer[sfTakerGets]) == t.takerGets); - BEAST_EXPECT( - get(acctOffer[sfTakerPays]) == t.takerPays); + BEAST_EXPECT(acctOffer[sfTakerGets] == t.takerGets); + BEAST_EXPECT(acctOffer[sfTakerPays] == t.takerPays); } } @@ -3853,7 +3848,7 @@ class OfferBaseUtil_test : public beast::unit_test::suite auto const& offer = *offerPtr; BEAST_EXPECT(offer[sfLedgerEntryType] == ltOFFER); BEAST_EXPECT( - get(offer[sfTakerGets]) == + offer[sfTakerGets] == STAmount(JPY.issue(), std::uint64_t(2230682446713524ul), -12)); BEAST_EXPECT(offer[sfTakerPays] == BTC(0.035378)); } @@ -3918,10 +3913,10 @@ class OfferBaseUtil_test : public beast::unit_test::suite auto const& offer = *offerPtr; BEAST_EXPECT(offer[sfLedgerEntryType] == ltOFFER); BEAST_EXPECT( - get(offer[sfTakerGets]) == + offer[sfTakerGets] == STAmount(USD.issue(), std::uint64_t(2185847305256635), -14)); BEAST_EXPECT( - get(offer[sfTakerPays]) == + offer[sfTakerPays] == STAmount(JPY.issue(), std::uint64_t(2286608293434156), -12)); } } @@ -4109,8 +4104,7 @@ class OfferBaseUtil_test : public beast::unit_test::suite actorOffers.begin(), actorOffers.end(), [](std::shared_ptr& offer) { - return get((*offer)[sfTakerGets]) - .signum() == 0; + return (*offer)[sfTakerGets].signum() == 0; })); BEAST_EXPECT(offerCount == actor.offers); @@ -4267,8 +4261,7 @@ class OfferBaseUtil_test : public beast::unit_test::suite actorOffers.begin(), actorOffers.end(), [](std::shared_ptr& offer) { - return get((*offer)[sfTakerGets]) - .signum() == 0; + return (*offer)[sfTakerGets].signum() == 0; })); BEAST_EXPECT(offerCount == actor.offers); @@ -4817,8 +4810,7 @@ class OfferBaseUtil_test : public beast::unit_test::suite offers.emplace( (*sle)[sfSequence], std::make_pair( - get((*sle)[sfTakerPays]), - get((*sle)[sfTakerGets]))); + (*sle)[sfTakerPays], (*sle)[sfTakerGets])); }); // first offer diff --git a/src/test/app/PayStrand_test.cpp b/src/test/app/PayStrand_test.cpp index ec3a9a9b605..f00a7361292 100644 --- a/src/test/app/PayStrand_test.cpp +++ b/src/test/app/PayStrand_test.cpp @@ -483,7 +483,7 @@ struct ExistingElementPool auto const sle = v.read(keylet::account(a)); if (!sle) return; - auto const b = get((*sle)[sfBalance]); + auto const b = (*sle)[sfBalance]; totalXRP += b.mantissa(); }; for (auto const& a : accounts) @@ -504,13 +504,13 @@ struct ExistingElementPool auto const sle = v.read(k); if (!sle) return STAmount{}; - return get((*sle)[sfBalance]); + return (*sle)[sfBalance]; }; auto lineBalance = [](ReadView const& v, ripple::Keylet const& k) { auto const sle = v.read(k); if (!sle) return STAmount{}; - return get((*sle)[sfBalance]); + return (*sle)[sfBalance]; }; std::uint64_t totalXRP[2]{}; for (auto ai1 = accounts.begin(), aie = accounts.end(); ai1 != aie; diff --git a/src/test/app/ReducedOffer_test.cpp b/src/test/app/ReducedOffer_test.cpp index a59d0dcd534..a070051e435 100644 --- a/src/test/app/ReducedOffer_test.cpp +++ b/src/test/app/ReducedOffer_test.cpp @@ -134,14 +134,10 @@ class ReducedOffer_test : public beast::unit_test::suite Json::Value bobOffer = ledgerEntryOffer(env, bob, bobOfferSeq); - STAmount const reducedTakerGets = - get(amountFromJson( - sfTakerGets, - bobOffer[jss::node][sfTakerGets.jsonName])); - STAmount const reducedTakerPays = - get(amountFromJson( - sfTakerPays, - bobOffer[jss::node][sfTakerPays.jsonName])); + STAmount const reducedTakerGets = amountFromJson( + sfTakerGets, bobOffer[jss::node][sfTakerGets.jsonName]); + STAmount const reducedTakerPays = amountFromJson( + sfTakerPays, bobOffer[jss::node][sfTakerPays.jsonName]); STAmount const bobGot = env.balance(bob) + bobsFee - bobInitialBalance; BEAST_EXPECT(reducedTakerPays < newOffer.in); @@ -294,14 +290,12 @@ class ReducedOffer_test : public beast::unit_test::suite Json::Value aliceOffer = ledgerEntryOffer(env, alice, aliceOfferSeq); - STAmount const reducedTakerGets = - get(amountFromJson( - sfTakerGets, - aliceOffer[jss::node][sfTakerGets.jsonName])); - STAmount const reducedTakerPays = - get(amountFromJson( - sfTakerPays, - aliceOffer[jss::node][sfTakerPays.jsonName])); + STAmount const reducedTakerGets = amountFromJson( + sfTakerGets, + aliceOffer[jss::node][sfTakerGets.jsonName]); + STAmount const reducedTakerPays = amountFromJson( + sfTakerPays, + aliceOffer[jss::node][sfTakerPays.jsonName]); STAmount const aliceGot = env.balance(alice) - aliceInitialBalance; BEAST_EXPECT(reducedTakerPays < inLedger.in); @@ -618,10 +612,10 @@ class ReducedOffer_test : public beast::unit_test::suite Amounts jsonOfferToAmounts(Json::Value const& json) { - STAmount const in = get( - amountFromJson(sfTakerPays, json[sfTakerPays.jsonName])); - STAmount const out = get( - amountFromJson(sfTakerGets, json[sfTakerGets.jsonName])); + STAmount const in = + amountFromJson(sfTakerPays, json[sfTakerPays.jsonName]); + STAmount const out = + amountFromJson(sfTakerGets, json[sfTakerGets.jsonName]); return {in, out}; } diff --git a/src/test/app/Regression_test.cpp b/src/test/app/Regression_test.cpp index 609d425f1e9..f54a88ace00 100644 --- a/src/test/app/Regression_test.cpp +++ b/src/test/app/Regression_test.cpp @@ -86,7 +86,7 @@ struct Regression_test : public beast::unit_test::suite { auto const sle = next->read(keylet::account(Account("alice").id())); BEAST_EXPECT(sle); - auto balance = get(sle->getFieldAmount(sfBalance)); + auto balance = sle->getFieldAmount(sfBalance); BEAST_EXPECT(balance == aliceAmount); } @@ -108,7 +108,7 @@ struct Regression_test : public beast::unit_test::suite { auto const sle = next->read(keylet::account(Account("alice").id())); BEAST_EXPECT(sle); - auto balance = get(sle->getFieldAmount(sfBalance)); + auto balance = sle->getFieldAmount(sfBalance); BEAST_EXPECT(balance == XRP(0)); } @@ -194,7 +194,7 @@ struct Regression_test : public beast::unit_test::suite { BEAST_EXPECT(tx->getAccountID(sfAccount) == alice.id()); BEAST_EXPECT(tx->getTxnType() == ttACCOUNT_SET); - auto const fee = get(tx->getFieldAmount(sfFee)); + auto const fee = tx->getFieldAmount(sfFee); BEAST_EXPECT(fee == drops(expectedFees[i])); } } diff --git a/src/test/app/TxQ_test.cpp b/src/test/app/TxQ_test.cpp index a1df4d997b1..e7b70203c91 100644 --- a/src/test/app/TxQ_test.cpp +++ b/src/test/app/TxQ_test.cpp @@ -1257,10 +1257,8 @@ class TxQPosNegFlows_test : public beast::unit_test::suite // bankrupt Alice. Fails, because an account can't have // more than the minimum reserve in flight before the // last queued transaction - aliceFee = get(env.le(alice)->getFieldAmount(sfBalance)) - .xrp() - .drops() - - (62); + aliceFee = + env.le(alice)->getFieldAmount(sfBalance).xrp().drops() - (62); env(noop(alice), seq(aliceSeq), fee(aliceFee), @@ -1320,10 +1318,7 @@ class TxQPosNegFlows_test : public beast::unit_test::suite // with enough fee to bankrupt bob and make the // later transactions unable to pay their fees std::int64_t bobFee = - get(env.le(bob)->getFieldAmount(sfBalance)) - .xrp() - .drops() - - (9 * 10 - 1); + env.le(bob)->getFieldAmount(sfBalance).xrp().drops() - (9 * 10 - 1); env(noop(bob), seq(bobSeq + 5), fee(bobFee), @@ -1336,10 +1331,8 @@ class TxQPosNegFlows_test : public beast::unit_test::suite // // The attempt fails because the sum of bob's fees now exceeds the // (artificially lowered to 200 drops) account reserve. - bobFee = get(env.le(bob)->getFieldAmount(sfBalance)) - .xrp() - .drops() - - (9 * 10); + bobFee = + env.le(bob)->getFieldAmount(sfBalance).xrp().drops() - (9 * 10); env(noop(bob), seq(bobSeq + 5), fee(bobFee), diff --git a/src/test/jtx/PathSet.h b/src/test/jtx/PathSet.h index 55a084501e5..0f4c4ddd3dd 100644 --- a/src/test/jtx/PathSet.h +++ b/src/test/jtx/PathSet.h @@ -40,10 +40,8 @@ countOffers( forEachItem( *env.current(), account, [&](std::shared_ptr const& sle) { if (sle->getType() == ltOFFER && - get(sle->getFieldAmount(sfTakerPays)).issue() == - takerPays && - get(sle->getFieldAmount(sfTakerGets)).issue() == - takerGets) + sle->getFieldAmount(sfTakerPays).issue() == takerPays && + sle->getFieldAmount(sfTakerGets).issue() == takerGets) ++count; }); return count; @@ -60,8 +58,8 @@ countOffers( forEachItem( *env.current(), account, [&](std::shared_ptr const& sle) { if (sle->getType() == ltOFFER && - get(sle->getFieldAmount(sfTakerPays)) == takerPays && - get(sle->getFieldAmount(sfTakerGets)) == takerGets) + sle->getFieldAmount(sfTakerPays) == takerPays && + sle->getFieldAmount(sfTakerGets) == takerGets) ++count; }); return count; diff --git a/src/test/jtx/delivermin.h b/src/test/jtx/delivermin.h index 46e633dab20..95ca676c292 100644 --- a/src/test/jtx/delivermin.h +++ b/src/test/jtx/delivermin.h @@ -31,12 +31,15 @@ namespace jtx { class delivermin { private: - STAmount amount_; + STEitherAmount amount_; public: delivermin(STAmount const& amount) : amount_(amount) { } + delivermin(STMPTAmount const& amount) : amount_(amount) + { + } void operator()(Env&, JTx& jtx) const; diff --git a/src/test/jtx/impl/AMM.cpp b/src/test/jtx/impl/AMM.cpp index 9c5e17f7b75..c083b6df35c 100644 --- a/src/test/jtx/impl/AMM.cpp +++ b/src/test/jtx/impl/AMM.cpp @@ -221,7 +221,7 @@ AMM::balances( env_.journal); auto const lptAMMBalance = account ? ammLPHolds(*env_.current(), *amm, *account, env_.journal) - : get(amm->getFieldAmount(sfLPTokenBalance)); + : amm->getFieldAmount(sfLPTokenBalance); return {asset1Balance, asset2Balance, lptAMMBalance}; } return {STAmount{}, STAmount{}, STAmount{}}; @@ -253,7 +253,7 @@ AMM::getLPTokensBalance(std::optional const& account) const .iou(); if (auto const amm = env_.current()->read(keylet::amm(asset1_.issue(), asset2_.issue()))) - return get(amm->getFieldAmount(sfLPTokenBalance)).iou(); + return amm->getFieldAmount(sfLPTokenBalance).iou(); return IOUAmount{0}; } @@ -672,7 +672,7 @@ AMM::bid(BidArg const& arg) { auto const& auctionSlot = static_cast(amm->peekAtField(sfAuctionSlot)); - lastPurchasePrice_ = get(auctionSlot[sfPrice]).iou(); + lastPurchasePrice_ = auctionSlot[sfPrice].iou(); } } bidMin_ = std::nullopt; @@ -777,8 +777,7 @@ AMM::expectAuctionSlot(auto&& cb) const auto const slotInterval = ammAuctionTimeSlot( env_.app().timeKeeper().now().time_since_epoch().count(), auctionSlot); - auto const slotPrice = - get(auctionSlot[sfPrice]).iou(); + auto const slotPrice = auctionSlot[sfPrice].iou(); auto const authAccounts = auctionSlot.getFieldArray(sfAuthAccounts); return cb(slotFee, slotInterval, slotPrice, authAccounts); diff --git a/src/test/jtx/impl/Env.cpp b/src/test/jtx/impl/Env.cpp index b070d64f6e1..6f0f9e3fc73 100644 --- a/src/test/jtx/impl/Env.cpp +++ b/src/test/jtx/impl/Env.cpp @@ -185,7 +185,7 @@ Env::balance(Account const& account) const auto const sle = le(account); if (!sle) return XRP(0); - return {get(sle->getFieldAmount(sfBalance)), ""}; + return {sle->getFieldAmount(sfBalance), ""}; } PrettyAmount @@ -196,7 +196,7 @@ Env::balance(Account const& account, Issue const& issue) const auto const sle = le(keylet::line(account.id(), issue)); if (!sle) return {STAmount(issue, 0), account.name()}; - auto amount = get(sle->getFieldAmount(sfBalance)); + auto amount = sle->getFieldAmount(sfBalance); amount.setIssuer(issue.account); if (account.id() > issue.account) amount.negate(); diff --git a/src/test/jtx/impl/TestHelpers.cpp b/src/test/jtx/impl/TestHelpers.cpp index b7104820228..b8105b1a631 100644 --- a/src/test/jtx/impl/TestHelpers.cpp +++ b/src/test/jtx/impl/TestHelpers.cpp @@ -117,12 +117,11 @@ expectLine( low.setIssuer(accountLow ? account : issue.account); high.setIssuer(accountLow ? issue.account : account); - expectDefaultTrustLine = - get(sle->getFieldAmount(sfLowLimit)) == low && - get(sle->getFieldAmount(sfHighLimit)) == high; + expectDefaultTrustLine = sle->getFieldAmount(sfLowLimit) == low && + sle->getFieldAmount(sfHighLimit) == high; } - auto amount = get(sle->getFieldAmount(sfBalance)); + auto amount = sle->getFieldAmount(sfBalance); amount.setIssuer(value.issue().account); if (!accountLow) amount.negate(); @@ -155,11 +154,8 @@ expectOffers( ++cnt; if (std::find_if( toMatch.begin(), toMatch.end(), [&](auto const& a) { - return a.in == - get( - sle->getFieldAmount(sfTakerPays)) && - a.out == - get(sle->getFieldAmount(sfTakerGets)); + return a.in == sle->getFieldAmount(sfTakerPays) && + a.out == sle->getFieldAmount(sfTakerGets); }) != toMatch.end()) ++matched; } @@ -334,7 +330,7 @@ channelBalance(ReadView const& view, uint256 const& chan) auto const slep = view.read({ltPAYCHAN, chan}); if (!slep) return XRPAmount{-1}; - return get((*slep)[sfBalance]); + return (*slep)[sfBalance]; } bool diff --git a/src/test/jtx/impl/balance.cpp b/src/test/jtx/impl/balance.cpp index f2c67db512c..42330658eb0 100644 --- a/src/test/jtx/impl/balance.cpp +++ b/src/test/jtx/impl/balance.cpp @@ -35,8 +35,7 @@ balance::operator()(Env& env) const } else if (env.test.expect(sle)) { - env.test.expect( - get(sle->getFieldAmount(sfBalance)) == value_); + env.test.expect(sle->getFieldAmount(sfBalance) == value_); } } else @@ -48,7 +47,7 @@ balance::operator()(Env& env) const } else if (env.test.expect(sle)) { - auto amount = get(sle->getFieldAmount(sfBalance)); + auto amount = sle->getFieldAmount(sfBalance); amount.setIssuer(value_.issue().account); if (account_.id() > value_.issue().account) amount.negate(); diff --git a/src/test/jtx/sendmax.h b/src/test/jtx/sendmax.h index 495c61c33b8..86f23dc6894 100644 --- a/src/test/jtx/sendmax.h +++ b/src/test/jtx/sendmax.h @@ -31,12 +31,15 @@ namespace jtx { class sendmax { private: - STAmount amount_; + STEitherAmount amount_; public: sendmax(STAmount const& amount) : amount_(amount) { } + sendmax(STMPTAmount const& amount) : amount_(amount) + { + } void operator()(Env&, JTx& jtx) const; diff --git a/src/test/ledger/Invariants_test.cpp b/src/test/ledger/Invariants_test.cpp index 3b748b9998a..1fd1543f18b 100644 --- a/src/test/ledger/Invariants_test.cpp +++ b/src/test/ledger/Invariants_test.cpp @@ -106,7 +106,7 @@ class Invariants_test : public beast::unit_test::suite auto const sle = ac.view().peek(keylet::account(A1.id())); if (!sle) return false; - auto amt = get(sle->getFieldAmount(sfBalance)); + auto amt = sle->getFieldAmount(sfBalance); sle->setFieldAmount(sfBalance, amt + STAmount{500}); ac.view().update(sle); return true; diff --git a/src/xrpld/app/ledger/AcceptedLedgerTx.cpp b/src/xrpld/app/ledger/AcceptedLedgerTx.cpp index 3a60f0d5eb6..e1ad68dff37 100644 --- a/src/xrpld/app/ledger/AcceptedLedgerTx.cpp +++ b/src/xrpld/app/ledger/AcceptedLedgerTx.cpp @@ -57,7 +57,7 @@ AcceptedLedgerTx::AcceptedLedgerTx( if (mTxn->getTxnType() == ttOFFER_CREATE) { auto const& account = mTxn->getAccountID(sfAccount); - auto const amount = get(mTxn->getFieldAmount(sfTakerGets)); + auto const amount = mTxn->getFieldAmount(sfTakerGets); // If the offer create is not self funded then add the owner balance if (account != amount.issue().account) diff --git a/src/xrpld/app/ledger/Ledger.cpp b/src/xrpld/app/ledger/Ledger.cpp index 1c76745b1c6..bcd3b6d4ba7 100644 --- a/src/xrpld/app/ledger/Ledger.cpp +++ b/src/xrpld/app/ledger/Ledger.cpp @@ -643,11 +643,10 @@ Ledger::setup() oldFees = baseFee || reserveBase || reserveIncrement; } { - auto const baseFeeXRP = get(sle->at(~sfBaseFeeDrops)); - auto const reserveBaseXRP = - get(sle->at(~sfReserveBaseDrops)); + auto const baseFeeXRP = sle->at(~sfBaseFeeDrops); + auto const reserveBaseXRP = sle->at(~sfReserveBaseDrops); auto const reserveIncrementXRP = - get(sle->at(~sfReserveIncrementDrops)); + sle->at(~sfReserveIncrementDrops); auto assign = [&ret]( XRPAmount& dest, std::optional const& src) { diff --git a/src/xrpld/app/ledger/OrderBookDB.cpp b/src/xrpld/app/ledger/OrderBookDB.cpp index ff088d080c2..d0eddadbacb 100644 --- a/src/xrpld/app/ledger/OrderBookDB.cpp +++ b/src/xrpld/app/ledger/OrderBookDB.cpp @@ -274,10 +274,8 @@ OrderBookDB::processTxn( data->isFieldPresent(sfTakerGets)) { auto listeners = getBookListeners( - {get(data->getFieldAmount(sfTakerGets)) - .issue(), - get(data->getFieldAmount(sfTakerPays)) - .issue()}); + {data->getFieldAmount(sfTakerGets).issue(), + data->getFieldAmount(sfTakerPays).issue()}); if (listeners) listeners->publish(jvObj, havePublished); } diff --git a/src/xrpld/app/ledger/detail/LedgerToJson.cpp b/src/xrpld/app/ledger/detail/LedgerToJson.cpp index 25d7ae7b203..11f42cd66ec 100644 --- a/src/xrpld/app/ledger/detail/LedgerToJson.cpp +++ b/src/xrpld/app/ledger/detail/LedgerToJson.cpp @@ -208,7 +208,7 @@ fillJsonTx( txn->getTxnType() == ttOFFER_CREATE) { auto const account = txn->getAccountID(sfAccount); - auto const amount = get(txn->getFieldAmount(sfTakerGets)); + auto const amount = txn->getFieldAmount(sfTakerGets); // If the offer create is not self funded then add the // owner balance diff --git a/src/xrpld/app/misc/FeeVoteImpl.cpp b/src/xrpld/app/misc/FeeVoteImpl.cpp index 8a03f877351..af57314ef6d 100644 --- a/src/xrpld/app/misc/FeeVoteImpl.cpp +++ b/src/xrpld/app/misc/FeeVoteImpl.cpp @@ -217,7 +217,7 @@ FeeVoteImpl::doVoting( auto doVote = [](std::shared_ptr const& val, detail::VotableValue& value, SF_AMOUNT const& xrpField) { - if (auto const field = get(~val->at(~xrpField)); + if (auto const field = ~val->at(~xrpField); field && field->native()) { auto const vote = field->xrp(); diff --git a/src/xrpld/app/misc/NetworkOPs.cpp b/src/xrpld/app/misc/NetworkOPs.cpp index 0755cf1ae63..f7cdfa212a2 100644 --- a/src/xrpld/app/misc/NetworkOPs.cpp +++ b/src/xrpld/app/misc/NetworkOPs.cpp @@ -2198,17 +2198,15 @@ NetworkOPsImp::pubValidation(std::shared_ptr const& val) // (The ~ operator converts the Proxy to a std::optional, which // simplifies later operations) - if (auto const baseFeeXRP = get(~val->at(~sfBaseFeeDrops)); + if (auto const baseFeeXRP = ~val->at(~sfBaseFeeDrops); baseFeeXRP && baseFeeXRP->native()) jvObj[jss::base_fee] = baseFeeXRP->xrp().jsonClipped(); - if (auto const reserveBaseXRP = - get(~val->at(~sfReserveBaseDrops)); + if (auto const reserveBaseXRP = ~val->at(~sfReserveBaseDrops); reserveBaseXRP && reserveBaseXRP->native()) jvObj[jss::reserve_base] = reserveBaseXRP->xrp().jsonClipped(); - if (auto const reserveIncXRP = - get(~val->at(~sfReserveIncrementDrops)); + if (auto const reserveIncXRP = ~val->at(~sfReserveIncrementDrops); reserveIncXRP && reserveIncXRP->native()) jvObj[jss::reserve_inc] = reserveIncXRP->xrp().jsonClipped(); @@ -3155,8 +3153,7 @@ NetworkOPsImp::transJson( if (transaction->getTxnType() == ttOFFER_CREATE) { auto const account = transaction->getAccountID(sfAccount); - auto const amount = - get(transaction->getFieldAmount(sfTakerGets)); + auto const amount = transaction->getFieldAmount(sfTakerGets); // If the offer create is not self funded then add the owner balance if (account != amount.issue().account) @@ -4393,10 +4390,8 @@ NetworkOPsImp::getBookPage( if (sleOffer) { auto const uOfferOwnerID = sleOffer->getAccountID(sfAccount); - auto const& saTakerGets = - get(sleOffer->getFieldAmount(sfTakerGets)); - auto const& saTakerPays = - get(sleOffer->getFieldAmount(sfTakerPays)); + auto const& saTakerGets = sleOffer->getFieldAmount(sfTakerGets); + auto const& saTakerPays = sleOffer->getFieldAmount(sfTakerPays); STAmount saOwnerFunds; bool firstOwnerOffer(true); @@ -4548,10 +4543,8 @@ NetworkOPsImp::getBookPage( if (sleOffer) { auto const uOfferOwnerID = sleOffer->getAccountID(sfAccount); - auto const& saTakerGets = - get(sleOffer->getFieldAmount(sfTakerGets)); - auto const& saTakerPays = - get(sleOffer->getFieldAmount(sfTakerPays)); + auto const& saTakerGets = sleOffer->getFieldAmount(sfTakerGets); + auto const& saTakerPays = sleOffer->getFieldAmount(sfTakerPays); STAmount saDirRate = obIterator.getCurrentRate(); STAmount saOwnerFunds; diff --git a/src/xrpld/app/misc/detail/AMMUtils.cpp b/src/xrpld/app/misc/detail/AMMUtils.cpp index dd6f3d6a141..efc80cf17b6 100644 --- a/src/xrpld/app/misc/detail/AMMUtils.cpp +++ b/src/xrpld/app/misc/detail/AMMUtils.cpp @@ -104,8 +104,7 @@ ammHolds( issues->second, freezeHandling, j); - return std::make_tuple( - asset1, asset2, get(ammSle[sfLPTokenBalance])); + return std::make_tuple(asset1, asset2, ammSle[sfLPTokenBalance]); } STAmount @@ -182,14 +181,14 @@ ammAccountHolds( if (isXRP(issue)) { if (auto const sle = view.read(keylet::account(ammAccountID))) - return get((*sle)[sfBalance]); + return (*sle)[sfBalance]; } else if (auto const sle = view.read( keylet::line(ammAccountID, issue.account, issue.currency)); sle && !isFrozen(view, ammAccountID, issue.currency, issue.account)) { - auto amount = get((*sle)[sfBalance]); + auto amount = (*sle)[sfBalance]; if (ammAccountID > issue.account) amount.negate(); amount.setIssuer(issue.account); @@ -393,10 +392,8 @@ isOnlyLiquidityProvider( } if (sle->getFieldU16(sfLedgerEntryType) != ltRIPPLE_STATE) return Unexpected(tecINTERNAL); // LCOV_EXCL_LINE - auto const lowLimit = - get(sle->getFieldAmount(sfLowLimit)); - auto const highLimit = - get(sle->getFieldAmount(sfHighLimit)); + auto const lowLimit = sle->getFieldAmount(sfLowLimit); + auto const highLimit = sle->getFieldAmount(sfHighLimit); auto const isLPTrustline = lowLimit.getIssuer() == lpAccount || highLimit.getIssuer() == lpAccount; auto const isLPTokenTrustline = diff --git a/src/xrpld/app/misc/detail/TxQ.cpp b/src/xrpld/app/misc/detail/TxQ.cpp index e0b386af754..159a700cc3f 100644 --- a/src/xrpld/app/misc/detail/TxQ.cpp +++ b/src/xrpld/app/misc/detail/TxQ.cpp @@ -39,7 +39,7 @@ getFeeLevelPaid(ReadView const& view, STTx const& tx) { auto const [baseFee, effectiveFeePaid] = [&view, &tx]() { XRPAmount baseFee = calculateBaseFee(view, tx); - XRPAmount feePaid = get(tx[sfFee]).xrp(); + XRPAmount feePaid = tx[sfFee].xrp(); // If baseFee is 0 then the cost of a basic transaction is free, but we // need the effective fee level to be non-zero. @@ -1078,7 +1078,7 @@ TxQ::apply( Transactions stuck in the queue are mitigated by LastLedgerSeq and MaybeTx::retriesRemaining. */ - auto const balance = get((*sleAccount)[sfBalance]).xrp(); + auto const balance = (*sleAccount)[sfBalance].xrp(); /* Get the minimum possible account reserve. If it is at least 10 * the base fee, and fees exceed this amount, the transaction can't be queued. diff --git a/src/xrpld/app/paths/Credit.cpp b/src/xrpld/app/paths/Credit.cpp index 5e632fd4d7d..c11f628a11d 100644 --- a/src/xrpld/app/paths/Credit.cpp +++ b/src/xrpld/app/paths/Credit.cpp @@ -37,8 +37,8 @@ creditLimit( if (sleRippleState) { - result = get(sleRippleState->getFieldAmount( - account < issuer ? sfLowLimit : sfHighLimit)); + result = sleRippleState->getFieldAmount( + account < issuer ? sfLowLimit : sfHighLimit); result.setIssuer(account); } @@ -70,7 +70,7 @@ creditBalance( if (sleRippleState) { - result = get(sleRippleState->getFieldAmount(sfBalance)); + result = sleRippleState->getFieldAmount(sfBalance); if (account < issuer) result.negate(); result.setIssuer(account); diff --git a/src/xrpld/app/paths/TrustLine.cpp b/src/xrpld/app/paths/TrustLine.cpp index 949a02a7ed8..6390c8d2117 100644 --- a/src/xrpld/app/paths/TrustLine.cpp +++ b/src/xrpld/app/paths/TrustLine.cpp @@ -29,9 +29,9 @@ TrustLineBase::TrustLineBase( std::shared_ptr const& sle, AccountID const& viewAccount) : key_(sle->key()) - , mLowLimit(get(sle->getFieldAmount(sfLowLimit))) - , mHighLimit(get(sle->getFieldAmount(sfHighLimit))) - , mBalance(get(sle->getFieldAmount(sfBalance))) + , mLowLimit(sle->getFieldAmount(sfLowLimit)) + , mHighLimit(sle->getFieldAmount(sfHighLimit)) + , mBalance(sle->getFieldAmount(sfBalance)) , mFlags(sle->getFieldU32(sfFlags)) , mViewLowest(mLowLimit.getIssuer() == viewAccount) { diff --git a/src/xrpld/app/tx/detail/AMMBid.cpp b/src/xrpld/app/tx/detail/AMMBid.cpp index 308f140791e..9de3762d2e3 100644 --- a/src/xrpld/app/tx/detail/AMMBid.cpp +++ b/src/xrpld/app/tx/detail/AMMBid.cpp @@ -40,10 +40,6 @@ AMMBid::preflight(PreflightContext const& ctx) if (auto const ret = preflight1(ctx); !isTesSuccess(ret)) return ret; - if (ctx.rules.enabled(featureMPTokensV1) && - (isMPT(ctx.tx[~sfBidMin]) || isMPT(ctx.tx[~sfBidMax]))) - return temMPT_INVALID_USAGE; - if (ctx.tx.getFlags() & tfUniversalMask) { JLOG(ctx.j.debug()) << "AMM Bid: invalid flags."; @@ -56,7 +52,7 @@ AMMBid::preflight(PreflightContext const& ctx) return res; } - if (auto const bidMin = get(ctx.tx[~sfBidMin])) + if (auto const bidMin = ctx.tx[~sfBidMin]) { if (auto const res = invalidAMMAmount(*bidMin)) { @@ -65,7 +61,7 @@ AMMBid::preflight(PreflightContext const& ctx) } } - if (auto const bidMax = get(ctx.tx[~sfBidMax])) + if (auto const bidMax = ctx.tx[~sfBidMax]) { if (auto const res = invalidAMMAmount(*bidMax)) { @@ -98,7 +94,7 @@ AMMBid::preclaim(PreclaimContext const& ctx) return terNO_AMM; } - auto const lpTokensBalance = get((*ammSle)[sfLPTokenBalance]); + auto const lpTokensBalance = (*ammSle)[sfLPTokenBalance]; if (lpTokensBalance == beast::zero) return tecAMM_EMPTY; @@ -123,7 +119,7 @@ AMMBid::preclaim(PreclaimContext const& ctx) return tecAMM_INVALID_TOKENS; } - auto const bidMin = get(ctx.tx[~sfBidMin]); + auto const bidMin = ctx.tx[~sfBidMin]; if (bidMin) { @@ -139,7 +135,7 @@ AMMBid::preclaim(PreclaimContext const& ctx) } } - auto const bidMax = get(ctx.tx[~sfBidMax]); + auto const bidMax = ctx.tx[~sfBidMax]; if (bidMax) { if (bidMax->issue() != lpTokens.issue()) @@ -175,7 +171,7 @@ applyBid( sb.peek(keylet::amm(ctx_.tx[sfAsset], ctx_.tx[sfAsset2])); if (!ammSle) return {tecINTERNAL, false}; - STAmount const lptAMMBalance = get((*ammSle)[sfLPTokenBalance]); + STAmount const lptAMMBalance = (*ammSle)[sfLPTokenBalance]; auto const lpTokens = ammLPHolds(sb, *ammSle, account_, ctx_.journal); auto const& rules = ctx_.view().rules(); if (!rules.enabled(fixInnerObjTemplate)) @@ -257,8 +253,8 @@ applyBid( TER res = tesSUCCESS; - auto const bidMin = get(ctx_.tx[~sfBidMin]); - auto const bidMax = get(ctx_.tx[~sfBidMax]); + auto const bidMin = ctx_.tx[~sfBidMin]; + auto const bidMax = ctx_.tx[~sfBidMax]; auto getPayPrice = [&](Number const& computedPrice) -> Expected { @@ -307,7 +303,7 @@ applyBid( else { // Price the slot was purchased at. - STAmount const pricePurchased = get(auctionSlot[sfPrice]); + STAmount const pricePurchased = auctionSlot[sfPrice]; assert(timeSlot); auto const fractionUsed = (Number(*timeSlot) + 1) / AUCTION_SLOT_TIME_INTERVALS; diff --git a/src/xrpld/app/tx/detail/AMMCreate.cpp b/src/xrpld/app/tx/detail/AMMCreate.cpp index 46dd9e583ab..35c4563e4d3 100644 --- a/src/xrpld/app/tx/detail/AMMCreate.cpp +++ b/src/xrpld/app/tx/detail/AMMCreate.cpp @@ -41,8 +41,7 @@ AMMCreate::preflight(PreflightContext const& ctx) if (auto const ret = preflight1(ctx); !isTesSuccess(ret)) return ret; - if (ctx.rules.enabled(featureMPTokensV1) && - (isMPT(ctx.tx[sfAmount]) || isMPT(ctx.tx[sfAmount2]))) + if (ctx.rules.enabled(featureMPTokensV1) && isMPT(ctx.tx[sfAmount])) return temMPT_NOT_SUPPORTED; if (ctx.tx.getFlags() & tfUniversalMask) @@ -52,7 +51,7 @@ AMMCreate::preflight(PreflightContext const& ctx) } auto const amount = get(ctx.tx[sfAmount]); - auto const amount2 = get(ctx.tx[sfAmount2]); + auto const amount2 = ctx.tx[sfAmount2]; if (amount.issue() == amount2.issue()) { @@ -94,7 +93,7 @@ AMMCreate::preclaim(PreclaimContext const& ctx) { auto const accountID = ctx.tx[sfAccount]; auto const amount = get(ctx.tx[sfAmount]); - auto const amount2 = get(ctx.tx[sfAmount2]); + auto const amount2 = ctx.tx[sfAmount2]; // Check if AMM already exists for the token pair if (auto const ammKeylet = keylet::amm(amount.issue(), amount2.issue()); @@ -213,7 +212,7 @@ applyCreate( beast::Journal j_) { auto const amount = get(ctx_.tx[sfAmount]); - auto const amount2 = get(ctx_.tx[sfAmount2]); + auto const amount2 = ctx_.tx[sfAmount2]; auto const ammKeylet = keylet::amm(amount.issue(), amount2.issue()); diff --git a/src/xrpld/app/tx/detail/AMMDelete.cpp b/src/xrpld/app/tx/detail/AMMDelete.cpp index 43cc05c3168..89ce34052d2 100644 --- a/src/xrpld/app/tx/detail/AMMDelete.cpp +++ b/src/xrpld/app/tx/detail/AMMDelete.cpp @@ -58,7 +58,7 @@ AMMDelete::preclaim(PreclaimContext const& ctx) return terNO_AMM; } - auto const lpTokensBalance = get((*ammSle)[sfLPTokenBalance]); + auto const lpTokensBalance = (*ammSle)[sfLPTokenBalance]; if (lpTokensBalance != beast::zero) return tecAMM_NOT_EMPTY; diff --git a/src/xrpld/app/tx/detail/AMMDeposit.cpp b/src/xrpld/app/tx/detail/AMMDeposit.cpp index 7f9b0c093e7..a83a0b101c0 100644 --- a/src/xrpld/app/tx/detail/AMMDeposit.cpp +++ b/src/xrpld/app/tx/detail/AMMDeposit.cpp @@ -41,13 +41,8 @@ AMMDeposit::preflight(PreflightContext const& ctx) if (auto const ret = preflight1(ctx); !isTesSuccess(ret)) return ret; - if (ctx.rules.enabled(featureMPTokensV1)) - { - if (isMPT(ctx.tx[~sfAmount]) || isMPT(ctx.tx[~sfAmount2])) - return temMPT_NOT_SUPPORTED; - if (isMPT(ctx.tx[~sfEPrice]) || isMPT(ctx.tx[~sfLPTokenOut])) - return temMPT_INVALID_USAGE; - } + if (ctx.rules.enabled(featureMPTokensV1) && isMPT(ctx.tx[~sfAmount])) + return temMPT_NOT_SUPPORTED; auto const flags = ctx.tx.getFlags(); if (flags & tfDepositMask) @@ -57,9 +52,9 @@ AMMDeposit::preflight(PreflightContext const& ctx) } auto const amount = get(ctx.tx[~sfAmount]); - auto const amount2 = get(ctx.tx[~sfAmount2]); - auto const ePrice = get(ctx.tx[~sfEPrice]); - auto const lpTokens = get(ctx.tx[~sfLPTokenOut]); + auto const amount2 = ctx.tx[~sfAmount2]; + auto const ePrice = ctx.tx[~sfEPrice]; + auto const lpTokens = ctx.tx[~sfLPTokenOut]; auto const tradingFee = ctx.tx[~sfTradingFee]; // Valid options for the flags are: // tfLPTokens: LPTokenOut, [Amount, Amount2] @@ -231,8 +226,7 @@ AMMDeposit::preclaim(PreclaimContext const& ctx) auto balance = [&](auto const& deposit) -> TER { if (isXRP(deposit)) { - auto const lpIssue = - get((*ammSle)[sfLPTokenBalance]).issue(); + auto const lpIssue = (*ammSle)[sfLPTokenBalance].issue(); // Adjust the reserve if LP doesn't have LPToken trustline auto const sle = ctx.view.read( keylet::line(accountID, lpIssue.account, lpIssue.currency)); @@ -254,7 +248,7 @@ AMMDeposit::preclaim(PreclaimContext const& ctx) }; auto const amount = get(ctx.tx[~sfAmount]); - auto const amount2 = get(ctx.tx[~sfAmount2]); + auto const amount2 = ctx.tx[~sfAmount2]; auto const ammAccountID = ammSle->getAccountID(sfAccount); auto checkAmount = [&](std::optional const& amount, @@ -322,7 +316,7 @@ AMMDeposit::preclaim(PreclaimContext const& ctx) } // Equal deposit lp tokens - if (auto const lpTokens = get(ctx.tx[~sfLPTokenOut]); + if (auto const lpTokens = ctx.tx[~sfLPTokenOut]; lpTokens && lpTokens->issue() != lptAMMBalance.issue()) { JLOG(ctx.j.debug()) << "AMM Deposit: invalid LPTokens."; @@ -349,9 +343,9 @@ std::pair AMMDeposit::applyGuts(Sandbox& sb) { auto const amount = get(ctx_.tx[~sfAmount]); - auto const amount2 = get(ctx_.tx[~sfAmount2]); - auto const ePrice = get(ctx_.tx[~sfEPrice]); - auto const lpTokensDeposit = get(ctx_.tx[~sfLPTokenOut]); + auto const amount2 = ctx_.tx[~sfAmount2]; + auto const ePrice = ctx_.tx[~sfEPrice]; + auto const lpTokensDeposit = ctx_.tx[~sfLPTokenOut]; auto ammSle = sb.peek(keylet::amm(ctx_.tx[sfAsset], ctx_.tx[sfAsset2])); if (!ammSle) return {tecINTERNAL, false}; // LCOV_EXCL_LINE diff --git a/src/xrpld/app/tx/detail/AMMVote.cpp b/src/xrpld/app/tx/detail/AMMVote.cpp index dff94bf0d51..c4b6c612c63 100644 --- a/src/xrpld/app/tx/detail/AMMVote.cpp +++ b/src/xrpld/app/tx/detail/AMMVote.cpp @@ -93,7 +93,7 @@ applyVote( auto ammSle = sb.peek(keylet::amm(ctx_.tx[sfAsset], ctx_.tx[sfAsset2])); if (!ammSle) return {tecINTERNAL, false}; - STAmount const lptAMMBalance = get((*ammSle)[sfLPTokenBalance]); + STAmount const lptAMMBalance = (*ammSle)[sfLPTokenBalance]; auto const lpTokensNew = ammLPHolds(sb, *ammSle, account_, ctx_.journal); std::optional minTokens; std::size_t minPos{0}; diff --git a/src/xrpld/app/tx/detail/AMMWithdraw.cpp b/src/xrpld/app/tx/detail/AMMWithdraw.cpp index afc17690219..c6a70584a01 100644 --- a/src/xrpld/app/tx/detail/AMMWithdraw.cpp +++ b/src/xrpld/app/tx/detail/AMMWithdraw.cpp @@ -41,13 +41,8 @@ AMMWithdraw::preflight(PreflightContext const& ctx) if (auto const ret = preflight1(ctx); !isTesSuccess(ret)) return ret; - if (ctx.rules.enabled(featureMPTokensV1)) - { - if (isMPT(ctx.tx[~sfAmount]) || isMPT(ctx.tx[~sfAmount2])) - return temMPT_NOT_SUPPORTED; - if (isMPT(ctx.tx[~sfEPrice]) || isMPT(ctx.tx[~sfLPTokenIn])) - return temMPT_INVALID_USAGE; - } + if (ctx.rules.enabled(featureMPTokensV1) && isMPT(ctx.tx[~sfAmount])) + return temMPT_NOT_SUPPORTED; auto const flags = ctx.tx.getFlags(); if (flags & tfWithdrawMask) @@ -57,9 +52,9 @@ AMMWithdraw::preflight(PreflightContext const& ctx) } auto const amount = get(ctx.tx[~sfAmount]); - auto const amount2 = get(ctx.tx[~sfAmount2]); - auto const ePrice = get(ctx.tx[~sfEPrice]); - auto const lpTokens = get(ctx.tx[~sfLPTokenIn]); + auto const amount2 = ctx.tx[~sfAmount2]; + auto const ePrice = ctx.tx[~sfEPrice]; + auto const lpTokens = ctx.tx[~sfLPTokenIn]; // Valid combinations are: // LPTokens // tfWithdrawAll @@ -190,7 +185,7 @@ AMMWithdraw::preclaim(PreclaimContext const& ctx) } auto const amount = get(ctx.tx[~sfAmount]); - auto const amount2 = get(ctx.tx[~sfAmount2]); + auto const amount2 = ctx.tx[~sfAmount2]; auto const expected = ammHolds( ctx.view, @@ -261,8 +256,8 @@ AMMWithdraw::preclaim(PreclaimContext const& ctx) auto const lpTokens = ammLPHolds(ctx.view, *ammSle, ctx.tx[sfAccount], ctx.j); - auto const lpTokensWithdraw = tokensWithdraw( - lpTokens, get(ctx.tx[~sfLPTokenIn]), ctx.tx.getFlags()); + auto const lpTokensWithdraw = + tokensWithdraw(lpTokens, ctx.tx[~sfLPTokenIn], ctx.tx.getFlags()); if (lpTokens <= beast::zero) { @@ -282,7 +277,7 @@ AMMWithdraw::preclaim(PreclaimContext const& ctx) return tecAMM_INVALID_TOKENS; } - if (auto const ePrice = get(ctx.tx[~sfEPrice]); + if (auto const ePrice = ctx.tx[~sfEPrice]; ePrice && ePrice->issue() != lpTokens.issue()) { JLOG(ctx.j.debug()) << "AMM Withdraw: invalid EPrice."; @@ -304,8 +299,8 @@ std::pair AMMWithdraw::applyGuts(Sandbox& sb) { auto const amount = get(ctx_.tx[~sfAmount]); - auto const amount2 = get(ctx_.tx[~sfAmount2]); - auto const ePrice = get(ctx_.tx[~sfEPrice]); + auto const amount2 = ctx_.tx[~sfAmount2]; + auto const ePrice = ctx_.tx[~sfEPrice]; auto ammSle = sb.peek(keylet::amm(ctx_.tx[sfAsset], ctx_.tx[sfAsset2])); if (!ammSle) return {tecINTERNAL, false}; // LCOV_EXCL_LINE @@ -315,8 +310,8 @@ AMMWithdraw::applyGuts(Sandbox& sb) return {tecINTERNAL, false}; // LCOV_EXCL_LINE auto const lpTokens = ammLPHolds(ctx_.view(), *ammSle, ctx_.tx[sfAccount], ctx_.journal); - auto const lpTokensWithdraw = tokensWithdraw( - lpTokens, get(ctx_.tx[~sfLPTokenIn]), ctx_.tx.getFlags()); + auto const lpTokensWithdraw = + tokensWithdraw(lpTokens, ctx_.tx[~sfLPTokenIn], ctx_.tx.getFlags()); // Due to rounding, the LPTokenBalance of the last LP // might not match the LP's trustline balance @@ -330,7 +325,7 @@ AMMWithdraw::applyGuts(Sandbox& sb) { if (withinRelativeDistance( lpTokens, - get(ammSle->getFieldAmount(sfLPTokenBalance)), + ammSle->getFieldAmount(sfLPTokenBalance), Number{1, -3})) { ammSle->setFieldAmount(sfLPTokenBalance, lpTokens); diff --git a/src/xrpld/app/tx/detail/CashCheck.cpp b/src/xrpld/app/tx/detail/CashCheck.cpp index 4e537432053..f83aec8b6b6 100644 --- a/src/xrpld/app/tx/detail/CashCheck.cpp +++ b/src/xrpld/app/tx/detail/CashCheck.cpp @@ -424,7 +424,7 @@ CashCheck::doApply() return tecNO_LINE; SF_AMOUNT const& tweakedLimit = destLow ? sfLowLimit : sfHighLimit; - STEitherAmount const savedLimit = sleTrustLine->at(tweakedLimit); + STAmount const savedLimit = sleTrustLine->at(tweakedLimit); // Make sure the tweaked limits are restored when we leave scope. scope_exit fixup( @@ -439,7 +439,7 @@ CashCheck::doApply() // while flow runs. STAmount const bigAmount( trustLineIssue, STAmount::cMaxValue, STAmount::cMaxOffset); - sleTrustLine->at(tweakedLimit) = STEitherAmount{bigAmount}; + sleTrustLine->at(tweakedLimit) = bigAmount; } // Let flow() do the heavy lifting on a check for an IOU. diff --git a/src/xrpld/app/tx/detail/Change.cpp b/src/xrpld/app/tx/detail/Change.cpp index 56d005f7429..909f35fc799 100644 --- a/src/xrpld/app/tx/detail/Change.cpp +++ b/src/xrpld/app/tx/detail/Change.cpp @@ -38,11 +38,6 @@ Change::preflight(PreflightContext const& ctx) if (!isTesSuccess(ret)) return ret; - if (ctx.rules.enabled(featureMPTokensV1) && - (isMPT(ctx.tx[~sfBaseFeeDrops]) || isMPT(ctx.tx[~sfReserveBaseDrops]) || - isMPT(ctx.tx[~sfReserveIncrementDrops]))) - return temMPT_INVALID_USAGE; - auto account = ctx.tx.getAccountID(sfAccount); if (account != beast::zero) { @@ -51,7 +46,7 @@ Change::preflight(PreflightContext const& ctx) } // No point in going any further if the transaction fee is malformed. - auto const fee = get(ctx.tx.getFieldAmount(sfFee)); + auto const fee = ctx.tx.getFieldAmount(sfFee); if (!fee.native() || fee != beast::zero) { JLOG(ctx.j.warn()) << "Change: invalid fee"; @@ -186,8 +181,8 @@ Change::activateTrustLinesToSelfFix() return true; } - auto const& lo = get(tl->getFieldAmount(sfLowLimit)); - auto const& hi = get(tl->getFieldAmount(sfHighLimit)); + auto const& lo = tl->getFieldAmount(sfLowLimit); + auto const& hi = tl->getFieldAmount(sfHighLimit); if (lo != hi) { diff --git a/src/xrpld/app/tx/detail/Clawback.cpp b/src/xrpld/app/tx/detail/Clawback.cpp index d2cb619a84b..d46013960cf 100644 --- a/src/xrpld/app/tx/detail/Clawback.cpp +++ b/src/xrpld/app/tx/detail/Clawback.cpp @@ -137,7 +137,7 @@ preclaimHelper(PreclaimContext const& ctx) if (!sleRippleState) return tecNO_LINE; - STAmount const& balance = get((*sleRippleState)[sfBalance]); + STAmount const& balance = (*sleRippleState)[sfBalance]; // If balance is positive, issuer must have higher address than holder if (balance > beast::zero && issuer < holder) diff --git a/src/xrpld/app/tx/detail/CreateOffer.cpp b/src/xrpld/app/tx/detail/CreateOffer.cpp index 5c5ed56dbf1..7a6a723bac8 100644 --- a/src/xrpld/app/tx/detail/CreateOffer.cpp +++ b/src/xrpld/app/tx/detail/CreateOffer.cpp @@ -32,7 +32,7 @@ TxConsequences CreateOffer::makeTxConsequences(PreflightContext const& ctx) { auto calculateMaxXRPSpend = [](STTx const& tx) -> XRPAmount { - auto const& amount{get(tx[sfTakerGets])}; + auto const& amount{tx[sfTakerGets]}; return amount.native() ? amount.xrp() : beast::zero; }; @@ -84,8 +84,8 @@ CreateOffer::preflight(PreflightContext const& ctx) return temBAD_SEQUENCE; } - STAmount saTakerPays = get(tx[sfTakerPays]); - STAmount saTakerGets = get(tx[sfTakerGets]); + STAmount saTakerPays = tx[sfTakerPays]; + STAmount saTakerGets = tx[sfTakerGets]; if (!isLegalNet(saTakerPays) || !isLegalNet(saTakerGets)) return temBAD_AMOUNT; @@ -134,8 +134,8 @@ CreateOffer::preclaim(PreclaimContext const& ctx) { auto const id = ctx.tx[sfAccount]; - auto saTakerPays = get(ctx.tx[sfTakerPays]); - auto saTakerGets = get(ctx.tx[sfTakerGets]); + auto saTakerPays = ctx.tx[sfTakerPays]; + auto saTakerGets = ctx.tx[sfTakerGets]; auto const& uPaysIssuerID = saTakerPays.getIssuer(); auto const& uPaysCurrency = saTakerPays.getCurrency(); @@ -928,8 +928,8 @@ CreateOffer::applyGuts(Sandbox& sb, Sandbox& sbCancel) bool const bFillOrKill(uTxFlags & tfFillOrKill); bool const bSell(uTxFlags & tfSell); - auto saTakerPays = get(ctx_.tx[sfTakerPays]); - auto saTakerGets = get(ctx_.tx[sfTakerGets]); + auto saTakerPays = ctx_.tx[sfTakerPays]; + auto saTakerGets = ctx_.tx[sfTakerGets]; auto const cancelSequence = ctx_.tx[~sfOfferSequence]; diff --git a/src/xrpld/app/tx/detail/DID.cpp b/src/xrpld/app/tx/detail/DID.cpp index c772f77223b..6e5a3108c72 100644 --- a/src/xrpld/app/tx/detail/DID.cpp +++ b/src/xrpld/app/tx/detail/DID.cpp @@ -90,7 +90,7 @@ addSLE( // Check reserve availability for new object creation { - auto const balance = get((*sleAccount)[sfBalance]).xrp(); + auto const balance = STAmount((*sleAccount)[sfBalance]).xrp(); auto const reserve = ctx.view().fees().accountReserve((*sleAccount)[sfOwnerCount] + 1); diff --git a/src/xrpld/app/tx/detail/DeleteAccount.cpp b/src/xrpld/app/tx/detail/DeleteAccount.cpp index 80136cca832..fb2f3fc507f 100644 --- a/src/xrpld/app/tx/detail/DeleteAccount.cpp +++ b/src/xrpld/app/tx/detail/DeleteAccount.cpp @@ -347,10 +347,8 @@ DeleteAccount::doApply() return ter; // Transfer any XRP remaining after the fee is paid to the destination: - (*dst)[sfBalance] = - STEitherAmount{get((*dst)[sfBalance]) + mSourceBalance}; - (*src)[sfBalance] = - STEitherAmount{get((*src)[sfBalance]) - mSourceBalance}; + (*dst)[sfBalance] = (*dst)[sfBalance] + mSourceBalance; + (*src)[sfBalance] = (*src)[sfBalance] - mSourceBalance; ctx_.deliver(mSourceBalance); assert((*src)[sfBalance] == XRPAmount(0)); diff --git a/src/xrpld/app/tx/detail/Escrow.cpp b/src/xrpld/app/tx/detail/Escrow.cpp index 3d45095954b..bcf187262c5 100644 --- a/src/xrpld/app/tx/detail/Escrow.cpp +++ b/src/xrpld/app/tx/detail/Escrow.cpp @@ -212,7 +212,7 @@ EscrowCreate::doApply() // Check reserve and funds availability { - auto const balance = get((*sle)[sfBalance]).xrp(); + auto const balance = STAmount((*sle)[sfBalance]).xrp(); auto const reserve = ctx_.view().fees().accountReserve((*sle)[sfOwnerCount] + 1); @@ -276,8 +276,7 @@ EscrowCreate::doApply() } // Deduct owner's balance, increment owner count - (*sle)[sfBalance] = STEitherAmount{ - get((*sle)[sfBalance]) - get(ctx_.tx[sfAmount])}; + (*sle)[sfBalance] = (*sle)[sfBalance] - get(ctx_.tx[sfAmount]); adjustOwnerCount(ctx_.view(), sle, 1, ctx_.journal); ctx_.view().update(sle); @@ -497,8 +496,7 @@ EscrowFinish::doApply() } // Transfer amount to destination - (*sled)[sfBalance] = STEitherAmount{ - get((*sled)[sfBalance]) + get((*slep)[sfAmount])}; + (*sled)[sfBalance] = (*sled)[sfBalance] + get((*slep)[sfAmount]); ctx_.view().update(sled); // Adjust source owner count @@ -584,8 +582,7 @@ EscrowCancel::doApply() // Transfer amount back to owner, decrement owner count auto const sle = ctx_.view().peek(keylet::account(account)); - (*sle)[sfBalance] = STEitherAmount{ - get((*sle)[sfBalance]) + get((*slep)[sfAmount])}; + (*sle)[sfBalance] = (*sle)[sfBalance] + get((*slep)[sfAmount]); adjustOwnerCount(ctx_.view(), sle, -1, ctx_.journal); ctx_.view().update(sle); diff --git a/src/xrpld/app/tx/detail/InvariantCheck.cpp b/src/xrpld/app/tx/detail/InvariantCheck.cpp index bb23bbc4f8a..a19f4517343 100644 --- a/src/xrpld/app/tx/detail/InvariantCheck.cpp +++ b/src/xrpld/app/tx/detail/InvariantCheck.cpp @@ -68,7 +68,7 @@ TransactionFeeCheck::finalize( // We should never charge more for a transaction than the transaction // authorizes. It's possible to charge less in some circumstances. - if (fee > get(tx.getFieldAmount(sfFee)).xrp()) + if (fee > tx.getFieldAmount(sfFee).xrp()) { JLOG(j.fatal()) << "Invariant failed: fee paid is " << fee.drops() << " exceeds fee specified in transaction."; @@ -98,13 +98,13 @@ XRPNotCreated::visitEntry( switch (before->getType()) { case ltACCOUNT_ROOT: - drops_ -= get((*before)[sfBalance]).xrp().drops(); + drops_ -= (*before)[sfBalance].xrp().drops(); break; case ltPAYCHAN: - drops_ -= (get((*before)[sfAmount]) - - get((*before)[sfBalance])) - .xrp() - .drops(); + drops_ -= + (get((*before)[sfAmount]) - (*before)[sfBalance]) + .xrp() + .drops(); break; case ltESCROW: drops_ -= get((*before)[sfAmount]).xrp().drops(); @@ -119,12 +119,12 @@ XRPNotCreated::visitEntry( switch (after->getType()) { case ltACCOUNT_ROOT: - drops_ += get((*after)[sfBalance]).xrp().drops(); + drops_ += (*after)[sfBalance].xrp().drops(); break; case ltPAYCHAN: if (!isDelete) drops_ += (get((*after)[sfAmount]) - - get((*after)[sfBalance])) + (*after)[sfBalance]) .xrp() .drops(); break; @@ -193,10 +193,10 @@ XRPBalanceChecks::visitEntry( }; if (before && before->getType() == ltACCOUNT_ROOT) - bad_ |= isBad(get((*before)[sfBalance])); + bad_ |= isBad((*before)[sfBalance]); if (after && after->getType() == ltACCOUNT_ROOT) - bad_ |= isBad(get((*after)[sfBalance])); + bad_ |= isBad((*after)[sfBalance]); } bool @@ -237,14 +237,10 @@ NoBadOffers::visitEntry( }; if (before && before->getType() == ltOFFER) - bad_ |= isBad( - get((*before)[sfTakerPays]), - get((*before)[sfTakerGets])); + bad_ |= isBad((*before)[sfTakerPays], (*before)[sfTakerGets]); if (after && after->getType() == ltOFFER) - bad_ |= isBad( - get((*after)[sfTakerPays]), - get((*after)[sfTakerGets])); + bad_ |= isBad((*after)[sfTakerPays], (*after)[sfTakerGets]); } bool @@ -448,10 +444,8 @@ NoXRPTrustLines::visitEntry( // relying on .native() just in case native somehow // were systematically incorrect xrpTrustLine_ = - get(after->getFieldAmount(sfLowLimit)).issue() == - xrpIssue() || - get(after->getFieldAmount(sfHighLimit)).issue() == - xrpIssue(); + after->getFieldAmount(sfLowLimit).issue() == xrpIssue() || + after->getFieldAmount(sfHighLimit).issue() == xrpIssue(); } } diff --git a/src/xrpld/app/tx/detail/NFTokenAcceptOffer.cpp b/src/xrpld/app/tx/detail/NFTokenAcceptOffer.cpp index 782d8d5a23b..258a96a412d 100644 --- a/src/xrpld/app/tx/detail/NFTokenAcceptOffer.cpp +++ b/src/xrpld/app/tx/detail/NFTokenAcceptOffer.cpp @@ -36,10 +36,6 @@ NFTokenAcceptOffer::preflight(PreflightContext const& ctx) if (auto const ret = preflight1(ctx); !isTesSuccess(ret)) return ret; - if (ctx.rules.enabled(featureMPTokensV1) && - isMPT(ctx.tx[~sfNFTokenBrokerFee])) - return temMPT_INVALID_USAGE; - if (ctx.tx.getFlags() & tfNFTokenAcceptOfferMask) return temINVALID_FLAG; @@ -52,7 +48,7 @@ NFTokenAcceptOffer::preflight(PreflightContext const& ctx) // The `BrokerFee` field must not be present in direct mode but may be // present and greater than zero in brokered mode. - if (auto const bf = get(ctx.tx[~sfNFTokenBrokerFee])) + if (auto const bf = ctx.tx[~sfNFTokenBrokerFee]) { if (!bo || !so) return temMALFORMED; @@ -155,7 +151,7 @@ NFTokenAcceptOffer::preclaim(PreclaimContext const& ctx) // have, ensure that the seller will get at least as much as they want // to get *after* this fee is accounted for (but before the issuer's // cut, if any). - if (auto const brokerFee = get(ctx.tx[~sfNFTokenBrokerFee])) + if (auto const brokerFee = ctx.tx[~sfNFTokenBrokerFee]) { if (brokerFee->issue() != get((*bo)[sfAmount]).issue()) return tecNFTOKEN_BUY_SELL_MISMATCH; @@ -368,8 +364,7 @@ NFTokenAcceptOffer::transferNFToken( // the deduction of the potential offer price. A small caveat here is // that the balance has already deducted the transaction fee, meaning // that the reserve requirement is a few drops higher. - auto const buyerBalance = - get(sleBuyer->getFieldAmount(sfBalance)); + auto const buyerBalance = sleBuyer->getFieldAmount(sfBalance); auto const buyerOwnerCountAfter = sleBuyer->getFieldU32(sfOwnerCount); if (buyerOwnerCountAfter > buyerOwnerCountBefore) @@ -472,7 +467,7 @@ NFTokenAcceptOffer::doApply() // being paid out than the seller authorized. That would be bad! // Send the broker the amount they requested. - if (auto const cut = get(ctx_.tx[~sfNFTokenBrokerFee]); + if (auto const cut = ctx_.tx[~sfNFTokenBrokerFee]; cut && cut.value() != beast::zero) { if (auto const r = pay(buyer, account_, cut.value()); diff --git a/src/xrpld/app/tx/detail/Offer.h b/src/xrpld/app/tx/detail/Offer.h index 27dd4fd5fe0..a6f707ba561 100644 --- a/src/xrpld/app/tx/detail/Offer.h +++ b/src/xrpld/app/tx/detail/Offer.h @@ -183,8 +183,8 @@ TOffer::TOffer(SLE::pointer const& entry, Quality quality) , m_quality(quality) , m_account(m_entry->getAccountID(sfAccount)) { - auto const tp = get(m_entry->getFieldAmount(sfTakerPays)); - auto const tg = get(m_entry->getFieldAmount(sfTakerGets)); + auto const tp = m_entry->getFieldAmount(sfTakerPays); + auto const tg = m_entry->getFieldAmount(sfTakerGets); m_amounts.in = toAmount(tp); m_amounts.out = toAmount(tg); this->issIn_ = tp.issue(); @@ -199,8 +199,8 @@ inline TOffer::TOffer( , m_quality(quality) , m_account(m_entry->getAccountID(sfAccount)) , m_amounts( - get(m_entry->getFieldAmount(sfTakerPays)), - get(m_entry->getFieldAmount(sfTakerGets))) + m_entry->getFieldAmount(sfTakerPays), + m_entry->getFieldAmount(sfTakerGets)) { } diff --git a/src/xrpld/app/tx/detail/PayChan.cpp b/src/xrpld/app/tx/detail/PayChan.cpp index c7f20093302..e3a2e02e02d 100644 --- a/src/xrpld/app/tx/detail/PayChan.cpp +++ b/src/xrpld/app/tx/detail/PayChan.cpp @@ -149,11 +149,9 @@ closeChannel( if (!sle) return tefINTERNAL; - assert( - get((*slep)[sfAmount]) >= get((*slep)[sfBalance])); - (*sle)[sfBalance] = STEitherAmount{ - get((*sle)[sfBalance]) + get((*slep)[sfAmount]) - - get((*slep)[sfBalance])}; + assert(get((*slep)[sfAmount]) >= (*slep)[sfBalance]); + (*sle)[sfBalance] = (*sle)[sfBalance] + get((*slep)[sfAmount]) - + (*slep)[sfBalance]; adjustOwnerCount(view, sle, -1, j); view.update(sle); @@ -202,7 +200,7 @@ PayChanCreate::preclaim(PreclaimContext const& ctx) // Check reserve and funds availability { - auto const balance = get((*sle)[sfBalance]); + auto const balance = (*sle)[sfBalance]; auto const reserve = ctx.view.fees().accountReserve((*sle)[sfOwnerCount] + 1); @@ -265,7 +263,7 @@ PayChanCreate::doApply() // Funds held in this channel (*slep)[sfAmount] = ctx_.tx[sfAmount]; // Amount channel has already paid - (*slep)[sfBalance] = ctx_.tx[sfAmount].zeroed(); + (*slep)[sfBalance] = get(ctx_.tx[sfAmount]).zeroed(); (*slep)[sfAccount] = account; (*slep)[sfDestination] = dst; (*slep)[sfSettleDelay] = ctx_.tx[sfSettleDelay]; @@ -298,8 +296,7 @@ PayChanCreate::doApply() } // Deduct owner's balance, increment owner count - (*sle)[sfBalance] = STEitherAmount{ - get((*sle)[sfBalance]) - get(ctx_.tx[sfAmount])}; + (*sle)[sfBalance] = (*sle)[sfBalance] - get(ctx_.tx[sfAmount]); adjustOwnerCount(ctx_.view(), sle, 1, ctx_.journal); ctx_.view().update(sle); @@ -376,7 +373,7 @@ PayChanFund::doApply() { // Check reserve and funds availability - auto const balance = get((*sle)[sfBalance]); + auto const balance = (*sle)[sfBalance]; auto const reserve = ctx_.view().fees().accountReserve((*sle)[sfOwnerCount]); @@ -398,8 +395,7 @@ PayChanFund::doApply() get((*slep)[sfAmount]) + get(ctx_.tx[sfAmount])}; ctx_.view().update(slep); - (*sle)[sfBalance] = STEitherAmount{ - get((*sle)[sfBalance]) - get(ctx_.tx[sfAmount])}; + (*sle)[sfBalance] = (*sle)[sfBalance] - get(ctx_.tx[sfAmount]); ctx_.view().update(sle); return tesSUCCESS; @@ -413,7 +409,7 @@ PayChanClaim::preflight(PreflightContext const& ctx) if (auto const ret = preflight1(ctx); !isTesSuccess(ret)) return ret; - auto const bal = get(ctx.tx[~sfBalance]); + auto const bal = ctx.tx[~sfBalance]; if (bal && (!isXRP(*bal) || *bal <= beast::zero)) return temBAD_AMOUNT; @@ -491,11 +487,10 @@ PayChanClaim::doApply() if (ctx_.tx[~sfBalance]) { - auto const chanBalance = - get(slep->getFieldAmount(sfBalance)).xrp(); + auto const chanBalance = slep->getFieldAmount(sfBalance).xrp(); auto const chanFunds = get(slep->getFieldAmount(sfAmount)).xrp(); - auto const reqBalance = get(ctx_.tx[sfBalance]).xrp(); + auto const reqBalance = ctx_.tx[sfBalance].xrp(); if (txAccount == dst && !ctx_.tx[~sfSignature]) return temBAD_SIGNATURE; @@ -542,8 +537,7 @@ PayChanClaim::doApply() (*slep)[sfBalance] = ctx_.tx[sfBalance]; XRPAmount const reqDelta = reqBalance - chanBalance; assert(reqDelta >= beast::zero); - (*sled)[sfBalance] = - STEitherAmount{get((*sled)[sfBalance]) + reqDelta}; + (*sled)[sfBalance] = (*sled)[sfBalance] + reqDelta; ctx_.view().update(sled); ctx_.view().update(slep); } @@ -560,8 +554,7 @@ PayChanClaim::doApply() { // Channel will close immediately if dry or the receiver closes if (dst == txAccount || - get((*slep)[sfBalance]) == - get((*slep)[sfAmount])) + (*slep)[sfBalance] == get((*slep)[sfAmount])) return closeChannel( slep, ctx_.view(), k.key, ctx_.app.journal("View")); diff --git a/src/xrpld/app/tx/detail/Payment.cpp b/src/xrpld/app/tx/detail/Payment.cpp index 113df99eedb..51054d9c965 100644 --- a/src/xrpld/app/tx/detail/Payment.cpp +++ b/src/xrpld/app/tx/detail/Payment.cpp @@ -105,6 +105,13 @@ preflightHelper(PreflightContext const& ctx) isMPT(ctx.tx[~sfDeliverMin]))) return temDISABLED; + if constexpr (!std::is_same_v) + return temMALFORMED; + + if (auto const& deliverMin = ctx.tx[~sfDeliverMin]; + deliverMin && ctx.tx[sfAmount].isIssue() != deliverMin->isIssue()) + return temMALFORMED; + auto& tx = ctx.tx; auto& j = ctx.j; @@ -421,7 +428,7 @@ applyHelper( ctx.view().rules().enabled(featureDepositPreauth); bool const bRipple = - paths || sendMax || !(isNative(saDstAmount) || isMPT(saDstAmount)); + (paths || sendMax || !isNative(saDstAmount)) && !isMPT(saDstAmount); // If the destination has lsfDepositAuth set, then only direct XRP // payments (no intermediate steps) are allowed to the destination. @@ -553,8 +560,7 @@ applyHelper( // mPriorBalance is the balance on the sending account BEFORE the // fees were charged. We want to make sure we have enough reserve // to send. Allow final spend to use reserve for fee. - auto const mmm = std::max( - reserve, get(ctx.tx.getFieldAmount(sfFee)).xrp()); + auto const mmm = std::max(reserve, ctx.tx.getFieldAmount(sfFee).xrp()); if (priorBalance < saDstAmount.xrp() + mmm) { @@ -607,8 +613,7 @@ applyHelper( ctx.view().fees().accountReserve(0)}; if (saDstAmount > dstReserve || - get(sleDst->getFieldAmount(sfBalance)) > - dstReserve) + sleDst->getFieldAmount(sfBalance) > dstReserve) return tecNO_PERMISSION; } } @@ -617,8 +622,7 @@ applyHelper( // Do the arithmetic for the transfer and make the ledger change. sleSrc->setFieldAmount(sfBalance, sourceBalance - saDstAmount); sleDst->setFieldAmount( - sfBalance, - get(sleDst->getFieldAmount(sfBalance)) + saDstAmount); + sfBalance, sleDst->getFieldAmount(sfBalance) + saDstAmount); // Re-arm the password change fee if we can and need to. if ((sleDst->getFlags() & lsfPasswordSpent)) diff --git a/src/xrpld/app/tx/detail/SetOracle.cpp b/src/xrpld/app/tx/detail/SetOracle.cpp index 4d8ddaa6e5b..055143cc6fd 100644 --- a/src/xrpld/app/tx/detail/SetOracle.cpp +++ b/src/xrpld/app/tx/detail/SetOracle.cpp @@ -174,7 +174,7 @@ SetOracle::preclaim(PreclaimContext const& ctx) auto const reserve = ctx.view.fees().accountReserve( sleSetter->getFieldU32(sfOwnerCount) + adjustReserve); - auto const& balance = get(sleSetter->getFieldAmount(sfBalance)); + auto const& balance = sleSetter->getFieldAmount(sfBalance); if (balance < reserve) return tecINSUFFICIENT_RESERVE; diff --git a/src/xrpld/app/tx/detail/SetTrust.cpp b/src/xrpld/app/tx/detail/SetTrust.cpp index 173ed35003d..954fc6543f1 100644 --- a/src/xrpld/app/tx/detail/SetTrust.cpp +++ b/src/xrpld/app/tx/detail/SetTrust.cpp @@ -34,9 +34,6 @@ SetTrust::preflight(PreflightContext const& ctx) if (auto const ret = preflight1(ctx); !isTesSuccess(ret)) return ret; - if (ctx.rules.enabled(featureMPTokensV1) && isMPT(ctx.tx[~sfLimitAmount])) - return temMPT_INVALID_USAGE; - auto& tx = ctx.tx; auto& j = ctx.j; @@ -48,8 +45,7 @@ SetTrust::preflight(PreflightContext const& ctx) return temINVALID_FLAG; } - STAmount const saLimitAmount( - get(tx.getFieldAmount(sfLimitAmount))); + STAmount const saLimitAmount(tx.getFieldAmount(sfLimitAmount)); if (!isLegalNet(saLimitAmount)) return temBAD_AMOUNT; @@ -104,7 +100,7 @@ SetTrust::preclaim(PreclaimContext const& ctx) return tefNO_AUTH_REQUIRED; } - auto const saLimitAmount = get(ctx.tx[sfLimitAmount]); + auto const saLimitAmount = ctx.tx[sfLimitAmount]; auto const currency = saLimitAmount.getCurrency(); auto const uDstAccountID = saLimitAmount.getIssuer(); @@ -175,7 +171,7 @@ SetTrust::preclaim(PreclaimContext const& ctx) ctx.view.read({ltAMM, sleDst->getFieldH256(sfAMMID)})) { if (auto const lpTokens = - get(ammSle->getFieldAmount(sfLPTokenBalance)); + ammSle->getFieldAmount(sfLPTokenBalance); lpTokens == beast::zero) return tecAMM_EMPTY; else if (lpTokens.getCurrency() != saLimitAmount.getCurrency()) @@ -194,8 +190,7 @@ SetTrust::doApply() { TER terResult = tesSUCCESS; - STAmount const saLimitAmount( - get(ctx_.tx.getFieldAmount(sfLimitAmount))); + STAmount const saLimitAmount(ctx_.tx.getFieldAmount(sfLimitAmount)); bool const bQualityIn(ctx_.tx.isFieldPresent(sfQualityIn)); bool const bQualityOut(ctx_.tx.isFieldPresent(sfQualityOut)); @@ -299,7 +294,7 @@ SetTrust::doApply() // Balances // - saLowBalance = get(sleRippleState->getFieldAmount(sfBalance)); + saLowBalance = sleRippleState->getFieldAmount(sfBalance); saHighBalance = -saLowBalance; // @@ -309,12 +304,10 @@ SetTrust::doApply() sleRippleState->setFieldAmount( !bHigh ? sfLowLimit : sfHighLimit, saLimitAllow); - saLowLimit = !bHigh - ? saLimitAllow - : get(sleRippleState->getFieldAmount(sfLowLimit)); - saHighLimit = bHigh - ? saLimitAllow - : get(sleRippleState->getFieldAmount(sfHighLimit)); + saLowLimit = + !bHigh ? saLimitAllow : sleRippleState->getFieldAmount(sfLowLimit); + saHighLimit = + bHigh ? saLimitAllow : sleRippleState->getFieldAmount(sfHighLimit); // // Quality in diff --git a/src/xrpld/app/tx/detail/Transactor.cpp b/src/xrpld/app/tx/detail/Transactor.cpp index 4889e51d9c3..42e9f0677ab 100644 --- a/src/xrpld/app/tx/detail/Transactor.cpp +++ b/src/xrpld/app/tx/detail/Transactor.cpp @@ -100,7 +100,7 @@ preflight1(PreflightContext const& ctx) } // No point in going any further if the transaction fee is malformed. - auto const fee = get(ctx.tx.getFieldAmount(sfFee)); + auto const fee = ctx.tx.getFieldAmount(sfFee); if (!fee.native() || fee.negative() || !isLegalAmount(fee.xrp())) { JLOG(ctx.j.debug()) << "preflight1: invalid fee"; @@ -195,7 +195,7 @@ Transactor::checkFee(PreclaimContext const& ctx, XRPAmount baseFee) if (!ctx.tx[sfFee].native()) return temBAD_FEE; - auto const feePaid = get(ctx.tx[sfFee]).xrp(); + auto const feePaid = ctx.tx[sfFee].xrp(); if (!isLegalAmount(feePaid) || feePaid < beast::zero) return temBAD_FEE; @@ -222,7 +222,7 @@ Transactor::checkFee(PreclaimContext const& ctx, XRPAmount baseFee) if (!sle) return terNO_ACCOUNT; - auto const balance = get((*sle)[sfBalance]).xrp(); + auto const balance = (*sle)[sfBalance].xrp(); if (balance < feePaid) { @@ -245,7 +245,7 @@ Transactor::checkFee(PreclaimContext const& ctx, XRPAmount baseFee) TER Transactor::payFee() { - auto const feePaid = get(ctx_.tx[sfFee]).xrp(); + auto const feePaid = ctx_.tx[sfFee].xrp(); auto const sle = view().peek(keylet::account(account_)); if (!sle) @@ -457,7 +457,7 @@ Transactor::apply() if (sle) { - mPriorBalance = STAmount{get((*sle)[sfBalance])}.xrp(); + mPriorBalance = STAmount{(*sle)[sfBalance]}.xrp(); mSourceBalance = mPriorBalance; TER result = consumeSeqProxy(sle); @@ -799,8 +799,7 @@ Transactor::reset(XRPAmount fee) // is missing then we can't very well charge it a fee, can we? return {tefINTERNAL, beast::zero}; - auto const balance = - get(txnAcct->getFieldAmount(sfBalance)).xrp(); + auto const balance = txnAcct->getFieldAmount(sfBalance).xrp(); // balance should have already been checked in checkFee / preFlight. assert(balance != beast::zero && (!view().open() || balance >= fee)); @@ -873,7 +872,7 @@ Transactor::operator()() stream << "preclaim result: " << transToken(result); bool applied = isTesSuccess(result); - auto fee = get(ctx_.tx.getFieldAmount(sfFee)).xrp(); + auto fee = ctx_.tx.getFieldAmount(sfFee).xrp(); if (ctx_.size() > oversizeMetaDataCap) result = tecOVERSIZE; @@ -922,8 +921,8 @@ Transactor::operator()() assert(before && after); if (doOffers && before && after && (before->getType() == ltOFFER) && - (get(before->getFieldAmount(sfTakerPays)) == - get(after->getFieldAmount(sfTakerPays)))) + (before->getFieldAmount(sfTakerPays) == + after->getFieldAmount(sfTakerPays))) { // Removal of offer found or made unfunded removedOffers.push_back(index); diff --git a/src/xrpld/app/tx/detail/XChainBridge.cpp b/src/xrpld/app/tx/detail/XChainBridge.cpp index 0e0ab3079aa..9b45f692274 100644 --- a/src/xrpld/app/tx/detail/XChainBridge.cpp +++ b/src/xrpld/app/tx/detail/XChainBridge.cpp @@ -446,7 +446,7 @@ transferHelper( auto const reserve = psb.fees().accountReserve(ownerCount); auto const availableBalance = [&]() -> STAmount { - STAmount const curBal = get((*sleSrc)[sfBalance]); + STAmount const curBal = (*sleSrc)[sfBalance]; // Checking that account == src and postFeeBalance == curBal is // not strictly nessisary, but helps protect against future // changes @@ -488,10 +488,8 @@ transferHelper( psb.insert(sleDst); } - (*sleSrc)[sfBalance] = - STEitherAmount{get((*sleSrc)[sfBalance]) - amt}; - (*sleDst)[sfBalance] = STEitherAmount{ - sfBalance, get((*sleDst)[sfBalance]) + amt}; + (*sleSrc)[sfBalance] = (*sleSrc)[sfBalance] - amt; + (*sleDst)[sfBalance] = STAmount{sfBalance, (*sleDst)[sfBalance] + amt}; psb.update(sleSrc); psb.update(sleDst); @@ -935,7 +933,7 @@ applyClaimAttestations( return ScopeResult{ newAttResult, - get((*sleClaimID)[sfSignatureReward]), + (*sleClaimID)[sfSignatureReward], (*sleClaimID)[sfAccount]}; }(); @@ -1060,7 +1058,7 @@ applyCreateAccountAttestations( return Unexpected(tecINTERNAL); // Check reserve - auto const balance = get((*sleDoor)[sfBalance]); + auto const balance = (*sleDoor)[sfBalance]; auto const reserve = psb.fees().accountReserve((*sleDoor)[sfOwnerCount] + 1); @@ -1216,8 +1214,7 @@ attestationPreflight(PreflightContext const& ctx) if (auto const ret = preflight1(ctx); !isTesSuccess(ret)) return ret; - if (ctx.rules.enabled(featureMPTokensV1) && - (isMPT(ctx.tx[sfAmount]) || isMPT(ctx.tx[~sfSignatureReward]))) + if (ctx.rules.enabled(featureMPTokensV1) && isMPT(ctx.tx[sfAmount])) return temMPT_NOT_SUPPORTED; if (ctx.tx.getFlags() & tfUniversalMask) @@ -1387,11 +1384,6 @@ XChainCreateBridge::preflight(PreflightContext const& ctx) if (auto const ret = preflight1(ctx); !isTesSuccess(ret)) return ret; - if (ctx.rules.enabled(featureMPTokensV1) && - (isMPT(ctx.tx[sfSignatureReward]) || - isMPT(ctx.tx[~sfMinAccountCreateAmount]))) - return temMPT_NOT_SUPPORTED; - if (ctx.tx.getFlags() & tfUniversalMask) return temINVALID_FLAG; @@ -1507,7 +1499,7 @@ XChainCreateBridge::preclaim(PreclaimContext const& ctx) if (!sleAcc) return terNO_ACCOUNT; - auto const balance = get((*sleAcc)[sfBalance]); + auto const balance = (*sleAcc)[sfBalance]; auto const reserve = ctx.view.fees().accountReserve((*sleAcc)[sfOwnerCount] + 1); @@ -1573,11 +1565,6 @@ BridgeModify::preflight(PreflightContext const& ctx) if (auto const ret = preflight1(ctx); !isTesSuccess(ret)) return ret; - if (ctx.rules.enabled(featureMPTokensV1) && - (isMPT(ctx.tx[~sfSignatureReward]) || - isMPT(ctx.tx[~sfMinAccountCreateAmount]))) - return temMPT_NOT_SUPPORTED; - if (ctx.tx.getFlags() & tfBridgeModifyMask) return temINVALID_FLAG; @@ -1871,7 +1858,7 @@ XChainClaim::doApply() (*sleClaimID)[sfAccount], sendingAmount, srcChain, - get((*sleClaimID)[sfSignatureReward]), + (*sleClaimID)[sfSignatureReward], }; }(); @@ -2089,7 +2076,7 @@ XChainCreateClaimID::preclaim(PreclaimContext const& ctx) if (!sleAcc) return terNO_ACCOUNT; - auto const balance = get((*sleAcc)[sfBalance]); + auto const balance = (*sleAcc)[sfBalance]; auto const reserve = ctx.view.fees().accountReserve((*sleAcc)[sfOwnerCount] + 1); @@ -2219,7 +2206,7 @@ XChainCreateAccountCommit::preflight(PreflightContext const& ctx) if (amount.signum() <= 0 || !amount.native()) return temBAD_AMOUNT; - auto const reward = get(ctx.tx[sfSignatureReward]); + auto const reward = ctx.tx[sfSignatureReward]; if (reward.signum() < 0 || !reward.native()) return temBAD_AMOUNT; @@ -2234,7 +2221,7 @@ XChainCreateAccountCommit::preclaim(PreclaimContext const& ctx) { STXChainBridge const bridgeSpec = ctx.tx[sfXChainBridge]; STAmount const amount = get(ctx.tx[sfAmount]); - STEitherAmount const reward = ctx.tx[sfSignatureReward]; + STAmount const reward = ctx.tx[sfSignatureReward]; auto const sleBridge = readBridge(ctx.view, bridgeSpec); if (!sleBridge) @@ -2248,7 +2235,7 @@ XChainCreateAccountCommit::preclaim(PreclaimContext const& ctx) } std::optional const minCreateAmount = - get((*sleBridge)[~sfMinAccountCreateAmount]); + (*sleBridge)[~sfMinAccountCreateAmount]; if (!minCreateAmount) return tecXCHAIN_CREATE_ACCOUNT_DISABLED; @@ -2295,7 +2282,7 @@ XChainCreateAccountCommit::doApply() AccountID const account = ctx_.tx[sfAccount]; STAmount const amount = get(ctx_.tx[sfAmount]); - STAmount const reward = get(ctx_.tx[sfSignatureReward]); + STAmount const reward = ctx_.tx[sfSignatureReward]; STXChainBridge const bridge = ctx_.tx[sfXChainBridge]; auto const sle = psb.peek(keylet::account(account)); diff --git a/src/xrpld/app/tx/detail/applySteps.cpp b/src/xrpld/app/tx/detail/applySteps.cpp index 3552b7a3574..48d19070eae 100644 --- a/src/xrpld/app/tx/detail/applySteps.cpp +++ b/src/xrpld/app/tx/detail/applySteps.cpp @@ -323,9 +323,8 @@ TxConsequences::TxConsequences(NotTEC pfresult) TxConsequences::TxConsequences(STTx const& tx) : isBlocker_(false) , fee_( - tx[sfFee].native() && !tx[sfFee].negative() - ? get(tx[sfFee]).xrp() - : beast::zero) + tx[sfFee].native() && !tx[sfFee].negative() ? tx[sfFee].xrp() + : beast::zero) , potentialSpend_(beast::zero) , seqProx_(tx.getSeqProxy()) , sequencesConsumed_(tx.getSeqProxy().isSeq() ? 1 : 0) diff --git a/src/xrpld/ledger/detail/PaymentSandbox.cpp b/src/xrpld/ledger/detail/PaymentSandbox.cpp index a25907626b4..d182d22b56c 100644 --- a/src/xrpld/ledger/detail/PaymentSandbox.cpp +++ b/src/xrpld/ledger/detail/PaymentSandbox.cpp @@ -299,13 +299,13 @@ PaymentSandbox::balanceChanges(ReadView const& view) const case ltACCOUNT_ROOT: lowID = xrpAccount(); highID = (*before)[sfAccount]; - oldBalance = get((*before)[sfBalance]); + oldBalance = (*before)[sfBalance]; newBalance = oldBalance.zeroed(); break; case ltRIPPLE_STATE: lowID = (*before)[sfLowLimit].getIssuer(); highID = (*before)[sfHighLimit].getIssuer(); - oldBalance = get((*before)[sfBalance]); + oldBalance = (*before)[sfBalance]; newBalance = oldBalance.zeroed(); break; case ltOFFER: @@ -324,13 +324,13 @@ PaymentSandbox::balanceChanges(ReadView const& view) const case ltACCOUNT_ROOT: lowID = xrpAccount(); highID = (*after)[sfAccount]; - newBalance = get((*after)[sfBalance]); + newBalance = (*after)[sfBalance]; oldBalance = newBalance.zeroed(); break; case ltRIPPLE_STATE: lowID = (*after)[sfLowLimit].getIssuer(); highID = (*after)[sfHighLimit].getIssuer(); - newBalance = get((*after)[sfBalance]); + newBalance = (*after)[sfBalance]; oldBalance = newBalance.zeroed(); break; case ltOFFER: @@ -350,14 +350,14 @@ PaymentSandbox::balanceChanges(ReadView const& view) const case ltACCOUNT_ROOT: lowID = xrpAccount(); highID = (*after)[sfAccount]; - oldBalance = get((*before)[sfBalance]); - newBalance = get((*after)[sfBalance]); + oldBalance = (*before)[sfBalance]; + newBalance = (*after)[sfBalance]; break; case ltRIPPLE_STATE: lowID = (*after)[sfLowLimit].getIssuer(); highID = (*after)[sfHighLimit].getIssuer(); - oldBalance = get((*before)[sfBalance]); - newBalance = get((*after)[sfBalance]); + oldBalance = (*before)[sfBalance]; + newBalance = (*after)[sfBalance]; break; case ltOFFER: // TBD diff --git a/src/xrpld/ledger/detail/View.cpp b/src/xrpld/ledger/detail/View.cpp index 403294d775d..6021ca75688 100644 --- a/src/xrpld/ledger/detail/View.cpp +++ b/src/xrpld/ledger/detail/View.cpp @@ -278,7 +278,7 @@ accountHolds( } else { - amount = get(sle->getFieldAmount(sfBalance)); + amount = sle->getFieldAmount(sfBalance); if (account > issuer) { // Put balance in account terms. @@ -430,7 +430,7 @@ xrpLiquid( ? XRPAmount{0} : view.fees().accountReserve(ownerCount); - auto const fullBalance = get(sle->getFieldAmount(sfBalance)); + auto const fullBalance = sle->getFieldAmount(sfBalance); auto const balance = view.balanceHook(id, xrpAccount(), fullBalance); @@ -1054,8 +1054,7 @@ rippleCredit( // If the line exists, modify it accordingly. if (auto const sleRippleState = view.peek(index)) { - STAmount saBalance = - get(sleRippleState->getFieldAmount(sfBalance)); + STAmount saBalance = sleRippleState->getFieldAmount(sfBalance); if (bSenderHigh) saBalance.negate(); // Put balance in sender terms. @@ -1090,8 +1089,8 @@ rippleCredit( view.read(keylet::account(uSenderID))->getFlags() & lsfDefaultRipple) && !(uFlags & (!bSenderHigh ? lsfLowFreeze : lsfHighFreeze)) && - !get(sleRippleState->getFieldAmount( - !bSenderHigh ? sfLowLimit : sfHighLimit)) + !sleRippleState->getFieldAmount( + !bSenderHigh ? sfLowLimit : sfHighLimit) // Sender trust limit is 0. && !sleRippleState->getFieldU32( !bSenderHigh ? sfLowQualityIn : sfHighQualityIn) @@ -1290,7 +1289,7 @@ accountSend( if (sender) { - if (get(sender->getFieldAmount(sfBalance)) < saAmount) + if (sender->getFieldAmount(sfBalance) < saAmount) { // VFALCO Its laborious to have to mutate the // TER based on params everywhere @@ -1299,8 +1298,7 @@ accountSend( } else { - auto const sndBal = - get(sender->getFieldAmount(sfBalance)); + auto const sndBal = sender->getFieldAmount(sfBalance); view.creditHook(uSenderID, xrpAccount(), saAmount, sndBal); // Decrement XRP balance. @@ -1312,7 +1310,7 @@ accountSend( if (tesSUCCESS == terResult && receiver) { // Increment XRP balance. - auto const rcvBal = get(receiver->getFieldAmount(sfBalance)); + auto const rcvBal = receiver->getFieldAmount(sfBalance); receiver->setFieldAmount(sfBalance, rcvBal + saAmount); view.creditHook(xrpAccount(), uReceiverID, saAmount, -rcvBal); @@ -1440,8 +1438,7 @@ updateTrustLine( flags & (!bSenderHigh ? lsfLowNoRipple : lsfHighNoRipple)) != static_cast(sle->getFlags() & lsfDefaultRipple) && !(flags & (!bSenderHigh ? lsfLowFreeze : lsfHighFreeze)) && - !get( - state->getFieldAmount(!bSenderHigh ? sfLowLimit : sfHighLimit)) + !state->getFieldAmount(!bSenderHigh ? sfLowLimit : sfHighLimit) // Sender trust limit is 0. && !state->getFieldU32(!bSenderHigh ? sfLowQualityIn : sfHighQualityIn) // Sender quality in is 0. @@ -1490,8 +1487,7 @@ issueIOU( if (auto state = view.peek(index)) { - STAmount final_balance = - get(state->getFieldAmount(sfBalance)); + STAmount final_balance = state->getFieldAmount(sfBalance); if (bSenderHigh) final_balance.negate(); // Put balance in sender terms. @@ -1586,8 +1582,7 @@ redeemIOU( if (auto state = view.peek(keylet::line(account, issue.account, issue.currency))) { - STAmount final_balance = - get(state->getFieldAmount(sfBalance)); + STAmount final_balance = state->getFieldAmount(sfBalance); if (bSenderHigh) final_balance.negate(); // Put balance in sender terms. @@ -1654,7 +1649,7 @@ transferXRP( JLOG(j.trace()) << "transferXRP: " << to_string(from) << " -> " << to_string(to) << ") : " << amount.getFullText(); - if (get(sender->getFieldAmount(sfBalance)) < amount) + if (sender->getFieldAmount(sfBalance) < amount) { // VFALCO Its unfortunate we have to keep // mutating these TER everywhere @@ -1665,11 +1660,11 @@ transferXRP( // Decrement XRP balance. sender->setFieldAmount( - sfBalance, get(sender->getFieldAmount(sfBalance)) - amount); + sfBalance, sender->getFieldAmount(sfBalance) - amount); view.update(sender); receiver->setFieldAmount( - sfBalance, get(receiver->getFieldAmount(sfBalance)) + amount); + sfBalance, receiver->getFieldAmount(sfBalance) + amount); view.update(receiver); return tesSUCCESS; diff --git a/src/xrpld/rpc/BookChanges.h b/src/xrpld/rpc/BookChanges.h index e7b9b026bc5..7d7978d3fe2 100644 --- a/src/xrpld/rpc/BookChanges.h +++ b/src/xrpld/rpc/BookChanges.h @@ -107,12 +107,10 @@ computeBookChanges(std::shared_ptr const& lpAccepted) // compute the difference in gets and pays actually // affected onto the offer - STAmount deltaGets = - get(finalFields.getFieldAmount(sfTakerGets)) - - get(previousFields.getFieldAmount(sfTakerGets)); - STAmount deltaPays = - get(finalFields.getFieldAmount(sfTakerPays)) - - get(previousFields.getFieldAmount(sfTakerPays)); + STAmount deltaGets = finalFields.getFieldAmount(sfTakerGets) - + previousFields.getFieldAmount(sfTakerGets); + STAmount deltaPays = finalFields.getFieldAmount(sfTakerPays) - + previousFields.getFieldAmount(sfTakerPays); std::string g{to_string(deltaGets.issue())}; std::string p{to_string(deltaPays.issue())}; diff --git a/src/xrpld/rpc/detail/TransactionSign.cpp b/src/xrpld/rpc/detail/TransactionSign.cpp index c5077a01a13..1fee84c683b 100644 --- a/src/xrpld/rpc/detail/TransactionSign.cpp +++ b/src/xrpld/rpc/detail/TransactionSign.cpp @@ -1202,7 +1202,7 @@ transactionSubmitMultiSigned( return rpcError(rpcSIGNING_MALFORMED); // The Fee field must be in XRP and greater than zero. - auto const fee = get(stpTrans->getFieldAmount(sfFee)); + auto const fee = stpTrans->getFieldAmount(sfFee); if (!isLegalNet(fee)) { diff --git a/src/xrpld/rpc/handlers/AMMInfo.cpp b/src/xrpld/rpc/handlers/AMMInfo.cpp index 3b4f03a7384..aad8faea213 100644 --- a/src/xrpld/rpc/handlers/AMMInfo.cpp +++ b/src/xrpld/rpc/handlers/AMMInfo.cpp @@ -189,7 +189,7 @@ doAMMInfo(RPC::JsonContext& context) context.j); auto const lptAMMBalance = accountID ? ammLPHolds(*ledger, *amm, *accountID, context.j) - : get((*amm)[sfLPTokenBalance]); + : (*amm)[sfLPTokenBalance]; Json::Value ammResult; asset1Balance.setJson(ammResult[jss::amount]); @@ -226,7 +226,7 @@ doAMMInfo(RPC::JsonContext& context) auctionSlot); auction[jss::time_interval] = timeSlot ? *timeSlot : AUCTION_SLOT_TIME_INTERVALS; - get(auctionSlot[sfPrice]).setJson(auction[jss::price]); + auctionSlot[sfPrice].setJson(auction[jss::price]); auction[jss::discounted_fee] = auctionSlot[sfDiscountedFee]; auction[jss::account] = to_string(auctionSlot.getAccountID(sfAccount)); diff --git a/src/xrpld/rpc/handlers/AccountOffers.cpp b/src/xrpld/rpc/handlers/AccountOffers.cpp index 75d02cdf59c..1a3b5227ed8 100644 --- a/src/xrpld/rpc/handlers/AccountOffers.cpp +++ b/src/xrpld/rpc/handlers/AccountOffers.cpp @@ -37,10 +37,8 @@ appendOfferJson(std::shared_ptr const& offer, Json::Value& offers) STAmount dirRate = amountFromQuality(getQuality(offer->getFieldH256(sfBookDirectory))); Json::Value& obj(offers.append(Json::objectValue)); - get(offer->getFieldAmount(sfTakerPays)) - .setJson(obj[jss::taker_pays]); - get(offer->getFieldAmount(sfTakerGets)) - .setJson(obj[jss::taker_gets]); + offer->getFieldAmount(sfTakerPays).setJson(obj[jss::taker_pays]); + offer->getFieldAmount(sfTakerGets).setJson(obj[jss::taker_gets]); obj[jss::seq] = offer->getFieldU32(sfSequence); obj[jss::flags] = offer->getFieldU32(sfFlags); obj[jss::quality] = dirRate.getText(); diff --git a/src/xrpld/rpc/handlers/NoRippleCheck.cpp b/src/xrpld/rpc/handlers/NoRippleCheck.cpp index ba533498494..e4012468434 100644 --- a/src/xrpld/rpc/handlers/NoRippleCheck.cpp +++ b/src/xrpld/rpc/handlers/NoRippleCheck.cpp @@ -169,20 +169,18 @@ doNoRippleCheck(RPC::JsonContext& context) if (needFix) { AccountID peer = - get(ownedItem->getFieldAmount( - bLow ? sfHighLimit : sfLowLimit)) + ownedItem + ->getFieldAmount(bLow ? sfHighLimit : sfLowLimit) .getIssuer(); - STAmount peerLimit = - get(ownedItem->getFieldAmount( - bLow ? sfHighLimit : sfLowLimit)); + STAmount peerLimit = ownedItem->getFieldAmount( + bLow ? sfHighLimit : sfLowLimit); problem += to_string(peerLimit.getCurrency()); problem += " line to "; problem += to_string(peerLimit.getIssuer()); problems.append(problem); - STAmount limitAmount( - get(ownedItem->getFieldAmount( - bLow ? sfLowLimit : sfHighLimit))); + STAmount limitAmount(ownedItem->getFieldAmount( + bLow ? sfLowLimit : sfHighLimit)); limitAmount.setIssuer(peer); Json::Value& tx = jvTransactions.append(Json::objectValue);