Format first-party source according to .clang-format

This commit is contained in:
Pretty Printer
2020-04-17 09:56:34 -05:00
committed by manojsdoshi
parent 65dfc5d19e
commit 50760c6935
1076 changed files with 86161 additions and 77449 deletions

View File

@@ -38,19 +38,17 @@ using TERUnderlyingType = int;
//------------------------------------------------------------------------------
enum TELcodes : TERUnderlyingType
{
enum TELcodes : TERUnderlyingType {
// Note: Range is stable.
// Exact numbers are used in ripple-binary-codec:
// https://github.com/ripple/ripple-binary-codec/blob/master/src/enums/definitions.json
// Use tokens.
// -399 .. -300: L Local error (transaction fee inadequate, exceeds local limit)
// Only valid during non-consensus processing.
// Implications:
// -399 .. -300: L Local error (transaction fee inadequate, exceeds local
// limit) Only valid during non-consensus processing. Implications:
// - Not forwarded
// - No fee check
telLOCAL_ERROR = -399,
telLOCAL_ERROR = -399,
telBAD_DOMAIN,
telBAD_PATH_COUNT,
telBAD_PUBLIC_KEY,
@@ -67,8 +65,7 @@ enum TELcodes : TERUnderlyingType
//------------------------------------------------------------------------------
enum TEMcodes : TERUnderlyingType
{
enum TEMcodes : TERUnderlyingType {
// Note: Range is stable.
// Exact numbers are used in ripple-binary-codec:
// https://github.com/ripple/ripple-binary-codec/blob/master/src/enums/definitions.json
@@ -82,7 +79,7 @@ enum TEMcodes : TERUnderlyingType
// - Not forwarded
// - Reject
// - Cannot succeed in any imagined ledger.
temMALFORMED = -299,
temMALFORMED = -299,
temBAD_AMOUNT,
temBAD_CURRENCY,
@@ -124,8 +121,7 @@ enum TEMcodes : TERUnderlyingType
//------------------------------------------------------------------------------
enum TEFcodes : TERUnderlyingType
{
enum TEFcodes : TERUnderlyingType {
// Note: Range is stable.
// Exact numbers are used in ripple-binary-codec:
// https://github.com/ripple/ripple-binary-codec/blob/master/src/enums/definitions.json
@@ -143,7 +139,7 @@ enum TEFcodes : TERUnderlyingType
// - Not applied
// - Not forwarded
// - Could succeed in an imagined ledger.
tefFAILURE = -199,
tefFAILURE = -199,
tefALREADY,
tefBAD_ADD_AUTH,
tefBAD_AUTH,
@@ -151,7 +147,7 @@ enum TEFcodes : TERUnderlyingType
tefCREATED,
tefEXCEPTION,
tefINTERNAL,
tefNO_AUTH_REQUIRED, // Can't set auth if auth is not required.
tefNO_AUTH_REQUIRED, // Can't set auth if auth is not required.
tefPAST_SEQ,
tefWRONG_PRIOR,
tefMASTER_DISABLED,
@@ -166,8 +162,7 @@ enum TEFcodes : TERUnderlyingType
//------------------------------------------------------------------------------
enum TERcodes : TERUnderlyingType
{
enum TERcodes : TERUnderlyingType {
// Note: Range is stable.
// Exact numbers are used in ripple-binary-codec:
// https://github.com/ripple/ripple-binary-codec/blob/master/src/enums/definitions.json
@@ -189,24 +184,23 @@ enum TERcodes : TERUnderlyingType
// - Might succeed later
// - Hold
// - Makes hole in sequence which jams transactions.
terRETRY = -99,
terFUNDS_SPENT, // This is a free transaction, so don't burden network.
terINSUF_FEE_B, // Can't pay fee, therefore don't burden network.
terNO_ACCOUNT, // Can't pay fee, therefore don't burden network.
terNO_AUTH, // Not authorized to hold IOUs.
terNO_LINE, // Internal flag.
terOWNERS, // Can't succeed with non-zero owner count.
terPRE_SEQ, // Can't pay fee, no point in forwarding, so don't
// burden network.
terLAST, // Process after all other transactions
terNO_RIPPLE, // Rippling not allowed
terQUEUED // Transaction is being held in TxQ until fee drops
terRETRY = -99,
terFUNDS_SPENT, // This is a free transaction, so don't burden network.
terINSUF_FEE_B, // Can't pay fee, therefore don't burden network.
terNO_ACCOUNT, // Can't pay fee, therefore don't burden network.
terNO_AUTH, // Not authorized to hold IOUs.
terNO_LINE, // Internal flag.
terOWNERS, // Can't succeed with non-zero owner count.
terPRE_SEQ, // Can't pay fee, no point in forwarding, so don't
// burden network.
terLAST, // Process after all other transactions
terNO_RIPPLE, // Rippling not allowed
terQUEUED // Transaction is being held in TxQ until fee drops
};
//------------------------------------------------------------------------------
enum TEScodes : TERUnderlyingType
{
enum TEScodes : TERUnderlyingType {
// Note: Exact number must stay stable. This code is stored by value
// in metadata for historic transactions.
@@ -216,13 +210,12 @@ enum TEScodes : TERUnderlyingType
// Implications:
// - Applied
// - Forwarded
tesSUCCESS = 0
tesSUCCESS = 0
};
//------------------------------------------------------------------------------
enum TECcodes : TERUnderlyingType
{
enum TECcodes : TERUnderlyingType {
// Note: Exact numbers must stay stable. These codes are stored by
// value in metadata for historic transactions.
@@ -243,104 +236,131 @@ enum TECcodes : TERUnderlyingType
// Otherwise, treated as terRETRY.
//
// DO NOT CHANGE THESE NUMBERS: They appear in ledger meta data.
tecCLAIM = 100,
tecPATH_PARTIAL = 101,
tecUNFUNDED_ADD = 102,
tecUNFUNDED_OFFER = 103,
tecUNFUNDED_PAYMENT = 104,
tecFAILED_PROCESSING = 105,
tecDIR_FULL = 121,
tecINSUF_RESERVE_LINE = 122,
tecINSUF_RESERVE_OFFER = 123,
tecNO_DST = 124,
tecNO_DST_INSUF_XRP = 125,
tecNO_LINE_INSUF_RESERVE = 126,
tecNO_LINE_REDUNDANT = 127,
tecPATH_DRY = 128,
tecUNFUNDED = 129, // Deprecated, old ambiguous unfunded.
tecNO_ALTERNATIVE_KEY = 130,
tecNO_REGULAR_KEY = 131,
tecOWNERS = 132,
tecNO_ISSUER = 133,
tecNO_AUTH = 134,
tecNO_LINE = 135,
tecINSUFF_FEE = 136,
tecFROZEN = 137,
tecNO_TARGET = 138,
tecNO_PERMISSION = 139,
tecNO_ENTRY = 140,
tecINSUFFICIENT_RESERVE = 141,
tecNEED_MASTER_KEY = 142,
tecDST_TAG_NEEDED = 143,
tecINTERNAL = 144,
tecOVERSIZE = 145,
tecCRYPTOCONDITION_ERROR = 146,
tecINVARIANT_FAILED = 147,
tecEXPIRED = 148,
tecDUPLICATE = 149,
tecKILLED = 150,
tecHAS_OBLIGATIONS = 151,
tecTOO_SOON = 152,
tecCLAIM = 100,
tecPATH_PARTIAL = 101,
tecUNFUNDED_ADD = 102,
tecUNFUNDED_OFFER = 103,
tecUNFUNDED_PAYMENT = 104,
tecFAILED_PROCESSING = 105,
tecDIR_FULL = 121,
tecINSUF_RESERVE_LINE = 122,
tecINSUF_RESERVE_OFFER = 123,
tecNO_DST = 124,
tecNO_DST_INSUF_XRP = 125,
tecNO_LINE_INSUF_RESERVE = 126,
tecNO_LINE_REDUNDANT = 127,
tecPATH_DRY = 128,
tecUNFUNDED = 129, // Deprecated, old ambiguous unfunded.
tecNO_ALTERNATIVE_KEY = 130,
tecNO_REGULAR_KEY = 131,
tecOWNERS = 132,
tecNO_ISSUER = 133,
tecNO_AUTH = 134,
tecNO_LINE = 135,
tecINSUFF_FEE = 136,
tecFROZEN = 137,
tecNO_TARGET = 138,
tecNO_PERMISSION = 139,
tecNO_ENTRY = 140,
tecINSUFFICIENT_RESERVE = 141,
tecNEED_MASTER_KEY = 142,
tecDST_TAG_NEEDED = 143,
tecINTERNAL = 144,
tecOVERSIZE = 145,
tecCRYPTOCONDITION_ERROR = 146,
tecINVARIANT_FAILED = 147,
tecEXPIRED = 148,
tecDUPLICATE = 149,
tecKILLED = 150,
tecHAS_OBLIGATIONS = 151,
tecTOO_SOON = 152,
};
//------------------------------------------------------------------------------
// For generic purposes, a free function that returns the value of a TE*codes.
constexpr TERUnderlyingType TERtoInt (TELcodes v)
{ return safe_cast<TERUnderlyingType>(v); }
constexpr TERUnderlyingType
TERtoInt(TELcodes v)
{
return safe_cast<TERUnderlyingType>(v);
}
constexpr TERUnderlyingType TERtoInt (TEMcodes v)
{ return safe_cast<TERUnderlyingType>(v); }
constexpr TERUnderlyingType
TERtoInt(TEMcodes v)
{
return safe_cast<TERUnderlyingType>(v);
}
constexpr TERUnderlyingType TERtoInt (TEFcodes v)
{ return safe_cast<TERUnderlyingType>(v); }
constexpr TERUnderlyingType
TERtoInt(TEFcodes v)
{
return safe_cast<TERUnderlyingType>(v);
}
constexpr TERUnderlyingType TERtoInt (TERcodes v)
{ return safe_cast<TERUnderlyingType>(v); }
constexpr TERUnderlyingType
TERtoInt(TERcodes v)
{
return safe_cast<TERUnderlyingType>(v);
}
constexpr TERUnderlyingType TERtoInt (TEScodes v)
{ return safe_cast<TERUnderlyingType>(v); }
constexpr TERUnderlyingType
TERtoInt(TEScodes v)
{
return safe_cast<TERUnderlyingType>(v);
}
constexpr TERUnderlyingType TERtoInt (TECcodes v)
{ return safe_cast<TERUnderlyingType>(v); }
constexpr TERUnderlyingType
TERtoInt(TECcodes v)
{
return safe_cast<TERUnderlyingType>(v);
}
//------------------------------------------------------------------------------
// Template class that is specific to selected ranges of error codes. The
// Trait tells std::enable_if which ranges are allowed.
template <template<typename> class Trait>
template <template <typename> class Trait>
class TERSubset
{
TERUnderlyingType code_;
public:
// Constructors
constexpr TERSubset() : code_ (tesSUCCESS) { }
constexpr TERSubset (TERSubset const& rhs) = default;
constexpr TERSubset (TERSubset&& rhs) = default;
private:
constexpr explicit TERSubset (int rhs) : code_ (rhs) { }
public:
static constexpr TERSubset fromInt (int from)
constexpr TERSubset() : code_(tesSUCCESS)
{
return TERSubset (from);
}
constexpr TERSubset(TERSubset const& rhs) = default;
constexpr TERSubset(TERSubset&& rhs) = default;
private:
constexpr explicit TERSubset(int rhs) : code_(rhs)
{
}
public:
static constexpr TERSubset
fromInt(int from)
{
return TERSubset(from);
}
// Trait tells enable_if which types are allowed for construction.
template <typename T, typename = std::enable_if_t<Trait<T>::value>>
constexpr TERSubset (T rhs)
: code_ (TERtoInt (rhs))
{ }
constexpr TERSubset(T rhs) : code_(TERtoInt(rhs))
{
}
// Assignment
constexpr TERSubset& operator=(TERSubset const& rhs) = default;
constexpr TERSubset& operator=(TERSubset&& rhs) = default;
constexpr TERSubset&
operator=(TERSubset const& rhs) = default;
constexpr TERSubset&
operator=(TERSubset&& rhs) = default;
// Trait tells enable_if which types are allowed for assignment.
template <typename T>
constexpr auto
operator= (T rhs) -> std::enable_if_t<Trait<T>::value, TERSubset&>
operator=(T rhs) -> std::enable_if_t<Trait<T>::value, TERSubset&>
{
code_ = TERtoInt (rhs);
code_ = TERtoInt(rhs);
return *this;
}
@@ -354,11 +374,12 @@ public:
// without casting.
operator Json::Value() const
{
return Json::Value {code_};
return Json::Value{code_};
}
// Streaming operator.
friend std::ostream& operator<< (std::ostream& os, TERSubset const& rhs)
friend std::ostream&
operator<<(std::ostream& os, TERSubset const& rhs)
{
return os << rhs.code_;
}
@@ -379,7 +400,8 @@ public:
// This code compiles with no errors or warnings if TER has an explicit
// (unnamed) conversion to int. To avoid silent conversions like these
// we provide (only) a named conversion.
friend constexpr TERUnderlyingType TERtoInt (TERSubset v)
friend constexpr TERUnderlyingType
TERtoInt(TERSubset v)
{
return v.code_;
}
@@ -389,54 +411,60 @@ public:
// Only enabled if both arguments return int if TERtiInt is called with them.
template <typename L, typename R>
constexpr auto
operator== (L const& lhs, R const& rhs) -> std::enable_if_t<
std::is_same<decltype (TERtoInt(lhs)), int>::value &&
std::is_same<decltype (TERtoInt(rhs)), int>::value, bool>
operator==(L const& lhs, R const& rhs) -> std::enable_if_t<
std::is_same<decltype(TERtoInt(lhs)), int>::value &&
std::is_same<decltype(TERtoInt(rhs)), int>::value,
bool>
{
return TERtoInt(lhs) == TERtoInt(rhs);
}
template <typename L, typename R>
constexpr auto
operator!= (L const& lhs, R const& rhs) -> std::enable_if_t<
std::is_same<decltype (TERtoInt(lhs)), int>::value &&
std::is_same<decltype (TERtoInt(rhs)), int>::value, bool>
operator!=(L const& lhs, R const& rhs) -> std::enable_if_t<
std::is_same<decltype(TERtoInt(lhs)), int>::value &&
std::is_same<decltype(TERtoInt(rhs)), int>::value,
bool>
{
return TERtoInt(lhs) != TERtoInt(rhs);
}
template <typename L, typename R>
constexpr auto
operator< (L const& lhs, R const& rhs) -> std::enable_if_t<
std::is_same<decltype (TERtoInt(lhs)), int>::value &&
std::is_same<decltype (TERtoInt(rhs)), int>::value, bool>
operator<(L const& lhs, R const& rhs) -> std::enable_if_t<
std::is_same<decltype(TERtoInt(lhs)), int>::value &&
std::is_same<decltype(TERtoInt(rhs)), int>::value,
bool>
{
return TERtoInt(lhs) < TERtoInt(rhs);
}
template <typename L, typename R>
constexpr auto
operator<= (L const& lhs, R const& rhs) -> std::enable_if_t<
std::is_same<decltype (TERtoInt(lhs)), int>::value &&
std::is_same<decltype (TERtoInt(rhs)), int>::value, bool>
operator<=(L const& lhs, R const& rhs) -> std::enable_if_t<
std::is_same<decltype(TERtoInt(lhs)), int>::value &&
std::is_same<decltype(TERtoInt(rhs)), int>::value,
bool>
{
return TERtoInt(lhs) <= TERtoInt(rhs);
}
template <typename L, typename R>
constexpr auto
operator> (L const& lhs, R const& rhs) -> std::enable_if_t<
std::is_same<decltype (TERtoInt(lhs)), int>::value &&
std::is_same<decltype (TERtoInt(rhs)), int>::value, bool>
operator>(L const& lhs, R const& rhs) -> std::enable_if_t<
std::is_same<decltype(TERtoInt(lhs)), int>::value &&
std::is_same<decltype(TERtoInt(rhs)), int>::value,
bool>
{
return TERtoInt(lhs) > TERtoInt(rhs);
}
template <typename L, typename R>
constexpr auto
operator>= (L const& lhs, R const& rhs) -> std::enable_if_t<
std::is_same<decltype (TERtoInt(lhs)), int>::value &&
std::is_same<decltype (TERtoInt(rhs)), int>::value, bool>
operator>=(L const& lhs, R const& rhs) -> std::enable_if_t<
std::is_same<decltype(TERtoInt(lhs)), int>::value &&
std::is_same<decltype(TERtoInt(rhs)), int>::value,
bool>
{
return TERtoInt(lhs) >= TERtoInt(rhs);
}
@@ -451,12 +479,30 @@ operator>= (L const& lhs, R const& rhs) -> std::enable_if_t<
// a tec code, then a malicious user could submit a transaction with a very
// large fee and have that fee charged against an account without using that
// account's valid signature.
template <typename FROM> class CanCvtToNotTEC : public std::false_type {};
template <> class CanCvtToNotTEC<TELcodes> : public std::true_type {};
template <> class CanCvtToNotTEC<TEMcodes> : public std::true_type {};
template <> class CanCvtToNotTEC<TEFcodes> : public std::true_type {};
template <> class CanCvtToNotTEC<TERcodes> : public std::true_type {};
template <> class CanCvtToNotTEC<TEScodes> : public std::true_type {};
template <typename FROM>
class CanCvtToNotTEC : public std::false_type
{
};
template <>
class CanCvtToNotTEC<TELcodes> : public std::true_type
{
};
template <>
class CanCvtToNotTEC<TEMcodes> : public std::true_type
{
};
template <>
class CanCvtToNotTEC<TEFcodes> : public std::true_type
{
};
template <>
class CanCvtToNotTEC<TERcodes> : public std::true_type
{
};
template <>
class CanCvtToNotTEC<TEScodes> : public std::true_type
{
};
using NotTEC = TERSubset<CanCvtToNotTEC>;
@@ -464,62 +510,92 @@ using NotTEC = TERSubset<CanCvtToNotTEC>;
// Use traits to build a TERSubset that can convert from any of the TE*codes
// enums as well as from NotTEC.
template <typename FROM> class CanCvtToTER : public std::false_type {};
template <> class CanCvtToTER<TELcodes> : public std::true_type {};
template <> class CanCvtToTER<TEMcodes> : public std::true_type {};
template <> class CanCvtToTER<TEFcodes> : public std::true_type {};
template <> class CanCvtToTER<TERcodes> : public std::true_type {};
template <> class CanCvtToTER<TEScodes> : public std::true_type {};
template <> class CanCvtToTER<TECcodes> : public std::true_type {};
template <> class CanCvtToTER<NotTEC> : public std::true_type {};
template <typename FROM>
class CanCvtToTER : public std::false_type
{
};
template <>
class CanCvtToTER<TELcodes> : public std::true_type
{
};
template <>
class CanCvtToTER<TEMcodes> : public std::true_type
{
};
template <>
class CanCvtToTER<TEFcodes> : public std::true_type
{
};
template <>
class CanCvtToTER<TERcodes> : public std::true_type
{
};
template <>
class CanCvtToTER<TEScodes> : public std::true_type
{
};
template <>
class CanCvtToTER<TECcodes> : public std::true_type
{
};
template <>
class CanCvtToTER<NotTEC> : public std::true_type
{
};
// TER allows all of the subsets.
using TER = TERSubset<CanCvtToTER>;
//------------------------------------------------------------------------------
inline bool isTelLocal(TER x)
inline bool
isTelLocal(TER x)
{
return ((x) >= telLOCAL_ERROR && (x) < temMALFORMED);
}
inline bool isTemMalformed(TER x)
inline bool
isTemMalformed(TER x)
{
return ((x) >= temMALFORMED && (x) < tefFAILURE);
}
inline bool isTefFailure(TER x)
inline bool
isTefFailure(TER x)
{
return ((x) >= tefFAILURE && (x) < terRETRY);
}
inline bool isTerRetry(TER x)
inline bool
isTerRetry(TER x)
{
return ((x) >= terRETRY && (x) < tesSUCCESS);
}
inline bool isTesSuccess(TER x)
inline bool
isTesSuccess(TER x)
{
return ((x) == tesSUCCESS);
}
inline bool isTecClaim(TER x)
inline bool
isTecClaim(TER x)
{
return ((x) >= tecCLAIM);
}
bool
transResultInfo (TER code, std::string& token, std::string& text);
transResultInfo(TER code, std::string& token, std::string& text);
std::string
transToken (TER code);
transToken(TER code);
std::string
transHuman (TER code);
transHuman(TER code);
boost::optional<TER>
transCode(std::string const& token);
} // ripple
} // namespace ripple
#endif