Files
rippled/include/xrpl/conditions/Condition.h
2026-07-13 10:40:40 +00:00

102 lines
2.3 KiB
C++

#pragma once
#include <xrpl/basics/Buffer.h>
#include <xrpl/basics/Slice.h>
#include <xrpl/conditions/detail/utils.h>
#include <cstddef>
#include <cstdint>
#include <memory>
#include <set>
#include <system_error>
#include <utility>
namespace xrpl::cryptoconditions {
enum class Type : std::uint8_t {
PreimageSha256 = 0,
PrefixSha256 = 1,
ThresholdSha256 = 2,
RsaSha256 = 3,
Ed25519Sha256 = 4
};
class Condition
{
public:
/**
* The largest binary condition we support.
*
* @note This value will be increased in the future, but it
* must never decrease, as that could cause conditions
* that were previously considered valid to no longer
* be allowed.
*/
static constexpr std::size_t kMaxSerializedCondition = 128;
/**
* Load a condition from its binary form
*
* @param s The buffer containing the fulfillment to load.
* @param ec Set to the error, if any occurred.
*
* The binary format for a condition is specified in the
* cryptoconditions RFC. See:
*
* https://tools.ietf.org/html/draft-thomas-crypto-conditions-02#section-7.2
*/
static std::unique_ptr<Condition>
deserialize(Slice s, std::error_code& ec);
public:
Type type;
/**
* An identifier for this condition.
*
* This fingerprint is meant to be unique only with
* respect to other conditions of the same type.
*/
Buffer fingerprint;
/**
* The cost associated with this condition.
*/
std::uint32_t cost;
/**
* For compound conditions, set of conditions includes
*/
std::set<Type> subtypes;
Condition(Type t, std::uint32_t c, Slice fp) : type(t), fingerprint(fp), cost(c)
{
}
Condition(Type t, std::uint32_t c, Buffer&& fp) : type(t), fingerprint(std::move(fp)), cost(c)
{
}
~Condition() = default;
Condition(Condition const&) = default;
Condition(Condition&&) = default;
Condition() = delete;
};
inline bool
operator==(Condition const& lhs, Condition const& rhs)
{
return lhs.type == rhs.type && lhs.cost == rhs.cost && lhs.subtypes == rhs.subtypes &&
lhs.fingerprint == rhs.fingerprint;
}
inline bool
operator!=(Condition const& lhs, Condition const& rhs)
{
return !(lhs == rhs);
}
} // namespace xrpl::cryptoconditions