Fix formatting

This commit is contained in:
Ed Hennis
2025-04-23 14:23:19 -04:00
parent 89f0b3b9e4
commit 939d3d4446
2 changed files with 247 additions and 253 deletions

View File

@@ -123,14 +123,14 @@ field_code(SerializedTypeID id, int index)
return (safe_cast<int>(id) << 16) | index;
}
// constexpr
// constexpr
inline int
field_code(int id, int index)
{
return (id << 16) | index;
}
/** Identifies fields.
/** Identifies fields.
Fields are necessary to tag data in signed transactions so that
the binary format of the transaction can be canonicalized. All
@@ -139,22 +139,20 @@ field_code(int id, int index)
Each SField, once constructed, lives until program termination, and
there is only one instance per fieldType/fieldValue pair which serves the
entire application.
*/
class SField
{
public:
*/
class SField
{
public:
enum {
sMD_Never = 0x00,
sMD_ChangeOrig = 0x01, // original value when it changes
sMD_ChangeNew = 0x02, // new value when it changes
sMD_DeleteFinal = 0x04, // final value when it is deleted
sMD_Create = 0x08, // value when it's created
sMD_Always =
0x10, // value when node containing it is affected at all
sMD_Always = 0x10, // value when node containing it is affected at all
sMD_BaseTen = 0x20, // value is treated as base 10, overriding
// default behavior
sMD_PseudoAccount =
0x40, // if this field is set in an ACCOUNT_ROOT
sMD_PseudoAccount = 0x40, // if this field is set in an ACCOUNT_ROOT
// _only_, then it is a pseudo-account
sMD_Default =
sMD_ChangeOrig | sMD_ChangeNew | sMD_DeleteFinal | sMD_Create
@@ -179,7 +177,7 @@ field_code(int id, int index)
SField&
operator=(SField&&) = delete;
public:
public:
struct private_access_tag_t; // public, but still an implementation
// detail
@@ -310,78 +308,78 @@ field_code(int id, int index)
return knownCodeToField;
}
private:
private:
static int num;
static std::map<int, SField const*> knownCodeToField;
static std::map<std::string, SField const*> knownNameToField;
};
};
/** A field with a type known at compile time. */
template <class T>
struct TypedField : SField
{
/** A field with a type known at compile time. */
template <class T>
struct TypedField : SField
{
using type = T;
template <class... Args>
explicit TypedField(private_access_tag_t pat, Args&&... args);
};
};
/** Indicate std::optional field semantics. */
template <class T>
struct OptionaledField
{
/** Indicate std::optional field semantics. */
template <class T>
struct OptionaledField
{
TypedField<T> const* f;
explicit OptionaledField(TypedField<T> const& f_) : f(&f_)
{
}
};
};
template <class T>
inline OptionaledField<T>
operator~(TypedField<T> const& f)
{
template <class T>
inline OptionaledField<T>
operator~(TypedField<T> const& f)
{
return OptionaledField<T>(f);
}
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
using SF_UINT8 = TypedField<STInteger<std::uint8_t>>;
using SF_UINT16 = TypedField<STInteger<std::uint16_t>>;
using SF_UINT32 = TypedField<STInteger<std::uint32_t>>;
using SF_UINT64 = TypedField<STInteger<std::uint64_t>>;
using SF_UINT96 = TypedField<STBitString<96>>;
using SF_UINT128 = TypedField<STBitString<128>>;
using SF_UINT160 = TypedField<STBitString<160>>;
using SF_UINT192 = TypedField<STBitString<192>>;
using SF_UINT256 = TypedField<STBitString<256>>;
using SF_UINT384 = TypedField<STBitString<384>>;
using SF_UINT512 = TypedField<STBitString<512>>;
using SF_UINT8 = TypedField<STInteger<std::uint8_t>>;
using SF_UINT16 = TypedField<STInteger<std::uint16_t>>;
using SF_UINT32 = TypedField<STInteger<std::uint32_t>>;
using SF_UINT64 = TypedField<STInteger<std::uint64_t>>;
using SF_UINT96 = TypedField<STBitString<96>>;
using SF_UINT128 = TypedField<STBitString<128>>;
using SF_UINT160 = TypedField<STBitString<160>>;
using SF_UINT192 = TypedField<STBitString<192>>;
using SF_UINT256 = TypedField<STBitString<256>>;
using SF_UINT384 = TypedField<STBitString<384>>;
using SF_UINT512 = TypedField<STBitString<512>>;
// These BIPS and TENTHBIPS values are serialized as the underlying type.
// The tag is only applied when deserialized.
//
// Basis points (bips) values:
using SF_BIPS16 = TypedField<STInteger<Bips16>>;
using SF_BIPS32 = TypedField<STInteger<Bips32>>;
// Tenth of a basis point values:
using SF_TENTHBIPS16 = TypedField<STInteger<TenthBips16>>;
using SF_TENTHBIPS32 = TypedField<STInteger<TenthBips32>>;
// These BIPS and TENTHBIPS values are serialized as the underlying type.
// The tag is only applied when deserialized.
//
// Basis points (bips) values:
using SF_BIPS16 = TypedField<STInteger<Bips16>>;
using SF_BIPS32 = TypedField<STInteger<Bips32>>;
// Tenth of a basis point values:
using SF_TENTHBIPS16 = TypedField<STInteger<TenthBips16>>;
using SF_TENTHBIPS32 = TypedField<STInteger<TenthBips32>>;
using SF_ACCOUNT = TypedField<STAccount>;
using SF_AMOUNT = TypedField<STAmount>;
using SF_ISSUE = TypedField<STIssue>;
using SF_CURRENCY = TypedField<STCurrency>;
using SF_NUMBER = TypedField<STNumber>;
using SF_VL = TypedField<STBlob>;
using SF_VECTOR256 = TypedField<STVector256>;
using SF_XCHAIN_BRIDGE = TypedField<STXChainBridge>;
using SF_ACCOUNT = TypedField<STAccount>;
using SF_AMOUNT = TypedField<STAmount>;
using SF_ISSUE = TypedField<STIssue>;
using SF_CURRENCY = TypedField<STCurrency>;
using SF_NUMBER = TypedField<STNumber>;
using SF_VL = TypedField<STBlob>;
using SF_VECTOR256 = TypedField<STVector256>;
using SF_XCHAIN_BRIDGE = TypedField<STXChainBridge>;
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// Use macros for most SField construction to enforce naming conventions.
// Use macros for most SField construction to enforce naming conventions.
#pragma push_macro("UNTYPED_SFIELD")
#undef UNTYPED_SFIELD
#pragma push_macro("TYPED_SFIELD")
@@ -393,12 +391,11 @@ field_code(int id, int index)
extern SField const sfName;
#define TYPED_SFIELD(sfName, stiSuffix, fieldValue, ...) \
extern SF_##stiSuffix const sfName;
#define INTERPRETED_SFIELD( \
sfName, stiSuffix, fieldValue, stiInterpreted, ...) \
#define INTERPRETED_SFIELD(sfName, stiSuffix, fieldValue, stiInterpreted, ...) \
extern SF_##stiInterpreted const sfName;
extern SField const sfInvalid;
extern SField const sfGeneric;
extern SField const sfInvalid;
extern SField const sfGeneric;
#include <xrpl/protocol/detail/sfields.macro>

View File

@@ -1098,14 +1098,11 @@ isPseudoAccount(std::shared_ptr<SLE const> sleAcct)
// semantics of true return value clean.
return sleAcct && sleAcct->getType() == ltACCOUNT_ROOT &&
std::count_if(
fields.begin(),
fields.end(),
[&sleAcct](SField const* sf) -> bool {
fields.begin(), fields.end(), [&sleAcct](SField const* sf) -> bool {
return sleAcct->isFieldPresent(*sf);
}) > 0;
}
Expected<std::shared_ptr<SLE>, TER>
createPseudoAccount(
ApplyView& view,