mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-02 00:15:50 +00:00
Reduce interface to STAccount (RIPD-994):
Since a non-default STAccount is now guaranteed to always be 160 bits, it was possible to reduce the number of methods that it provides. In the process of narrowing the STAccount interface it became reasonable to remove some methods that duplicated functionality. A few classes offered both a value() and a getValue() method. The getValue() method is removed from those classes.
This commit is contained in:
committed by
Nik Bougalis
parent
f72b14ec36
commit
289bc7deb3
@@ -136,15 +136,11 @@ TxMeta::getAffectedAccounts() const
|
||||
{
|
||||
for (auto const& field : *inner)
|
||||
{
|
||||
STAccount const* sa =
|
||||
dynamic_cast<STAccount const*> (&field);
|
||||
|
||||
if (sa)
|
||||
if (auto sa = dynamic_cast<STAccount const*> (&field))
|
||||
{
|
||||
AccountID id;
|
||||
assert(sa->isValueH160());
|
||||
if (sa->getValueH160(id))
|
||||
list.insert(id);
|
||||
assert (! sa->isDefault());
|
||||
if (! sa->isDefault())
|
||||
list.insert(sa->value());
|
||||
}
|
||||
else if ((field.getFName () == sfLowLimit) || (field.getFName () == sfHighLimit) ||
|
||||
(field.getFName () == sfTakerPays) || (field.getFName () == sfTakerGets))
|
||||
|
||||
@@ -22,7 +22,6 @@
|
||||
|
||||
#include <ripple/protocol/AccountID.h>
|
||||
#include <ripple/protocol/STBase.h>
|
||||
#include <ripple/protocol/STBlob.h>
|
||||
#include <string>
|
||||
|
||||
namespace ripple {
|
||||
@@ -95,7 +94,7 @@ public:
|
||||
STAccount&
|
||||
operator= (AccountID const& value)
|
||||
{
|
||||
setValueH160(value);
|
||||
setValue (value);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -103,34 +102,15 @@ public:
|
||||
value() const noexcept
|
||||
{
|
||||
AccountID result;
|
||||
getValueH160(result);
|
||||
result.copyFrom (value_);
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename Tag>
|
||||
void setValueH160 (base_uint<160, Tag> const& v)
|
||||
void setValue (AccountID const& v)
|
||||
{
|
||||
value_.copyFrom (v);
|
||||
default_ = false;
|
||||
}
|
||||
|
||||
// VFALCO This is a clumsy interface, it should return
|
||||
// the value. And it should not be possible to
|
||||
// have anything other than a uint160 in here.
|
||||
// The base_uint tag should always be `AccountIDTag`.
|
||||
template <typename Tag>
|
||||
bool getValueH160 (base_uint<160, Tag>& v) const
|
||||
{
|
||||
bool const success = isValueH160();
|
||||
if (success)
|
||||
v.copyFrom (value_);
|
||||
return success;
|
||||
}
|
||||
|
||||
bool isValueH160 () const
|
||||
{
|
||||
return ! isDefault();
|
||||
}
|
||||
};
|
||||
|
||||
} // ripple
|
||||
|
||||
@@ -98,12 +98,6 @@ public:
|
||||
s.addBitString<Bits> (value_);
|
||||
}
|
||||
|
||||
const value_type&
|
||||
getValue () const
|
||||
{
|
||||
return value_;
|
||||
}
|
||||
|
||||
template <typename Tag>
|
||||
void setValue (base_uint<Bits, Tag> const& v)
|
||||
{
|
||||
|
||||
@@ -147,12 +147,6 @@ public:
|
||||
return value_;
|
||||
}
|
||||
|
||||
Buffer
|
||||
getValue () const
|
||||
{
|
||||
return Buffer(value_.data (), value_.size ());
|
||||
}
|
||||
|
||||
void
|
||||
setValue (Buffer&& b)
|
||||
{
|
||||
|
||||
@@ -50,7 +50,7 @@ struct STExchange<STInteger<U>, T>
|
||||
get (boost::optional<T>& t,
|
||||
STInteger<U> const& u)
|
||||
{
|
||||
t = u.getValue();
|
||||
t = u.value();
|
||||
}
|
||||
|
||||
static
|
||||
|
||||
@@ -71,12 +71,6 @@ public:
|
||||
s.addInteger (value_);
|
||||
}
|
||||
|
||||
Integer
|
||||
getValue () const
|
||||
{
|
||||
return value_;
|
||||
}
|
||||
|
||||
STInteger& operator= (value_type const& v)
|
||||
{
|
||||
value_ = v;
|
||||
|
||||
@@ -487,7 +487,7 @@ public:
|
||||
operator[](OptionaledField<T> const& of) const;
|
||||
|
||||
/** Return a modifiable field value.
|
||||
|
||||
|
||||
Throws:
|
||||
|
||||
missing_field_error if the field is
|
||||
@@ -585,11 +585,11 @@ private:
|
||||
// Implementation for getting (most) fields that return by value.
|
||||
//
|
||||
// The remove_cv and remove_reference are necessitated by the STBitString
|
||||
// types. Their getValue returns by const ref. We return those types
|
||||
// types. Their value() returns by const ref. We return those types
|
||||
// by value.
|
||||
template <typename T, typename V =
|
||||
typename std::remove_cv < typename std::remove_reference <
|
||||
decltype (std::declval <T> ().getValue ())>::type >::type >
|
||||
decltype (std::declval <T> ().value ())>::type >::type >
|
||||
V getFieldByValue (SField const& field) const
|
||||
{
|
||||
const STBase* rf = peekAtPField (field);
|
||||
@@ -607,7 +607,7 @@ private:
|
||||
if (!cf)
|
||||
throw std::runtime_error ("Wrong field type");
|
||||
|
||||
return cf->getValue ();
|
||||
return cf->value ();
|
||||
}
|
||||
|
||||
// Implementations for getting (most) fields that return by const reference.
|
||||
|
||||
@@ -18,18 +18,12 @@
|
||||
//==============================================================================
|
||||
|
||||
#include <BeastConfig.h>
|
||||
#include <ripple/basics/Log.h>
|
||||
#include <ripple/json/json_reader.h>
|
||||
#include <ripple/json/to_string.h>
|
||||
#include <ripple/protocol/HashPrefix.h>
|
||||
#include <ripple/protocol/STObject.h>
|
||||
#include <ripple/protocol/InnerObjectFormats.h>
|
||||
#include <ripple/protocol/STBase.h>
|
||||
#include <ripple/protocol/STAccount.h>
|
||||
#include <ripple/protocol/STArray.h>
|
||||
#include <ripple/protocol/STObject.h>
|
||||
#include <ripple/protocol/STParsedJSON.h>
|
||||
#include <beast/module/core/text/LexicalCast.h>
|
||||
#include <memory>
|
||||
#include <ripple/protocol/STBlob.h>
|
||||
#include <ripple/basics/Log.h>
|
||||
|
||||
namespace ripple {
|
||||
|
||||
@@ -431,7 +425,7 @@ bool STObject::setFlag (std::uint32_t f)
|
||||
if (!t)
|
||||
return false;
|
||||
|
||||
t->setValue (t->getValue () | f);
|
||||
t->setValue (t->value () | f);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -442,7 +436,7 @@ bool STObject::clearFlag (std::uint32_t f)
|
||||
if (!t)
|
||||
return false;
|
||||
|
||||
t->setValue (t->getValue () & ~f);
|
||||
t->setValue (t->value () & ~f);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -458,7 +452,7 @@ std::uint32_t STObject::getFlags (void) const
|
||||
if (!t)
|
||||
return 0;
|
||||
|
||||
return t->getValue ();
|
||||
return t->value ();
|
||||
}
|
||||
|
||||
STBase* STObject::makeFieldPresent (SField const& field)
|
||||
@@ -560,22 +554,7 @@ uint256 STObject::getFieldH256 (SField const& field) const
|
||||
|
||||
AccountID STObject::getAccountID (SField const& field) const
|
||||
{
|
||||
auto rf = peekAtPField (field);
|
||||
if (!rf)
|
||||
throw std::runtime_error ("Field not found");
|
||||
|
||||
AccountID account;
|
||||
if (rf->getSType () != STI_NOTPRESENT)
|
||||
{
|
||||
const STAccount* cf = dynamic_cast<const STAccount*> (rf);
|
||||
|
||||
if (!cf)
|
||||
throw std::runtime_error ("Wrong field type");
|
||||
|
||||
cf->getValueH160 (account);
|
||||
}
|
||||
|
||||
return account;
|
||||
return getFieldByValue <STAccount> (field);
|
||||
}
|
||||
|
||||
Blob STObject::getFieldVL (SField const& field) const
|
||||
@@ -670,26 +649,12 @@ void STObject::setFieldV256 (SField const& field, STVector256 const& v)
|
||||
|
||||
void STObject::setAccountID (SField const& field, AccountID const& v)
|
||||
{
|
||||
STBase* rf = getPField (field, true);
|
||||
|
||||
if (!rf)
|
||||
throw std::runtime_error ("Field not found");
|
||||
|
||||
if (rf->getSType () == STI_NOTPRESENT)
|
||||
rf = makeFieldPresent (field);
|
||||
|
||||
STAccount* cf = dynamic_cast<STAccount*> (rf);
|
||||
|
||||
if (!cf)
|
||||
throw std::runtime_error ("Wrong field type");
|
||||
|
||||
cf->setValueH160 (v);
|
||||
setFieldUsingSetValue <STAccount> (field, v);
|
||||
}
|
||||
|
||||
void STObject::setFieldVL (SField const& field, Blob const& v)
|
||||
{
|
||||
setFieldUsingSetValue <STBlob>
|
||||
(field, Buffer(v.data (), v.size ()));
|
||||
setFieldUsingSetValue <STBlob> (field, Buffer(v.data (), v.size ()));
|
||||
}
|
||||
|
||||
void STObject::setFieldAmount (SField const& field, STAmount const& v)
|
||||
|
||||
@@ -134,10 +134,9 @@ STTx::getMentionedAccounts () const
|
||||
{
|
||||
if (auto sa = dynamic_cast<STAccount const*> (&it))
|
||||
{
|
||||
AccountID id;
|
||||
assert(sa->isValueH160());
|
||||
if (sa->getValueH160(id))
|
||||
list.insert(id);
|
||||
assert(! sa->isDefault());
|
||||
if (! sa->isDefault())
|
||||
list.insert(sa->value());
|
||||
}
|
||||
else if (auto sa = dynamic_cast<STAmount const*> (&it))
|
||||
{
|
||||
@@ -488,7 +487,7 @@ isAccountFieldOkay (STObject const& st)
|
||||
for (int i = 0; i < st.getCount(); ++i)
|
||||
{
|
||||
auto t = dynamic_cast<STAccount const*>(st.peekAtPIndex (i));
|
||||
if (t && !t->isValueH160 ())
|
||||
if (t && t->isDefault ())
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,6 @@ struct STAccount_test : public beast::unit_test::suite
|
||||
expect (defaultAcct.getText() == "");
|
||||
expect (defaultAcct.isDefault() == true);
|
||||
expect (defaultAcct.value() == AccountID {});
|
||||
expect (! defaultAcct.isValueH160());
|
||||
{
|
||||
#ifdef NDEBUG // Qualified because the serialization asserts in a debug build.
|
||||
Serializer s;
|
||||
@@ -45,7 +44,6 @@ struct STAccount_test : public beast::unit_test::suite
|
||||
SerialIter sit (s.slice ());
|
||||
STAccount const deserializedDefault (sit, sfAccount);
|
||||
expect (deserializedDefault.isEquivalent (defaultAcct));
|
||||
expect (! deserializedDefault.isValueH160());
|
||||
#endif // NDEBUG
|
||||
}
|
||||
{
|
||||
@@ -55,7 +53,6 @@ struct STAccount_test : public beast::unit_test::suite
|
||||
SerialIter sit (s.slice ());
|
||||
STAccount const deserializedDefault (sit, sfAccount);
|
||||
expect (deserializedDefault.isEquivalent (defaultAcct));
|
||||
expect (! deserializedDefault.isValueH160());
|
||||
}
|
||||
|
||||
// Test constructor from SField.
|
||||
@@ -64,7 +61,6 @@ struct STAccount_test : public beast::unit_test::suite
|
||||
expect (sfAcct.getText() == "");
|
||||
expect (sfAcct.isDefault());
|
||||
expect (sfAcct.value() == AccountID {});
|
||||
expect (! sfAcct.isValueH160());
|
||||
expect (sfAcct.isEquivalent (defaultAcct));
|
||||
{
|
||||
Serializer s;
|
||||
@@ -74,7 +70,6 @@ struct STAccount_test : public beast::unit_test::suite
|
||||
SerialIter sit (s.slice ());
|
||||
STAccount const deserializedSf (sit, sfAccount);
|
||||
expect (deserializedSf.isEquivalent(sfAcct));
|
||||
expect (! deserializedSf.isValueH160());
|
||||
}
|
||||
|
||||
// Test constructor from SField and AccountID.
|
||||
@@ -82,7 +77,6 @@ struct STAccount_test : public beast::unit_test::suite
|
||||
expect (zeroAcct.getText() == "rrrrrrrrrrrrrrrrrrrrrhoLvTp");
|
||||
expect (! zeroAcct.isDefault());
|
||||
expect (zeroAcct.value() == AccountID {0});
|
||||
expect (zeroAcct.isValueH160());
|
||||
expect (! zeroAcct.isEquivalent (defaultAcct));
|
||||
expect (! zeroAcct.isEquivalent (sfAcct));
|
||||
{
|
||||
@@ -94,7 +88,6 @@ struct STAccount_test : public beast::unit_test::suite
|
||||
SerialIter sit (s.slice ());
|
||||
STAccount const deserializedZero (sit, sfAccount);
|
||||
expect (deserializedZero.isEquivalent (zeroAcct));
|
||||
expect (deserializedZero.isValueH160());
|
||||
}
|
||||
{
|
||||
// Construct from a VL that is not exactly 160 bits.
|
||||
|
||||
Reference in New Issue
Block a user