xrpld
Loading...
Searching...
No Matches
Fulfillment.h
1#pragma once
2
3#include <xrpl/basics/Buffer.h>
4#include <xrpl/basics/Slice.h>
5#include <xrpl/conditions/Condition.h>
6
7#include <cstddef>
8#include <cstdint>
9#include <memory>
10#include <system_error>
11
12namespace xrpl::cryptoconditions {
13
15{
16public:
25 static constexpr std::size_t kMaxSerializedFulfillment = 256;
26
40
41public:
42 virtual ~Fulfillment() = default;
43
52 [[nodiscard]] virtual Buffer
53 fingerprint() const = 0;
54
58 [[nodiscard]] virtual Type
59 type() const = 0;
60
64 [[nodiscard]] virtual bool
65 validate(Slice data) const = 0;
66
74 [[nodiscard]] virtual std::uint32_t
75 cost() const = 0;
76
84 [[nodiscard]] virtual Condition
85 condition() const = 0;
86};
87
88inline bool
89operator==(Fulfillment const& lhs, Fulfillment const& rhs)
90{
91 // FIXME: for compound conditions, need to also check subtypes
92 return lhs.type() == rhs.type() && lhs.cost() == rhs.cost() &&
93 lhs.fingerprint() == rhs.fingerprint();
94}
95
99bool
100match(Fulfillment const& f, Condition const& c);
101
113bool
114validate(Fulfillment const& f, Condition const& c, Slice m);
115
130bool
131validate(Fulfillment const& f, Condition const& c);
132
133} // namespace xrpl::cryptoconditions
Like std::vector<char> but better.
Definition Buffer.h:19
An immutable linear range of bytes.
Definition Slice.h:28
bool match(Fulfillment const &f, Condition const &c)
Determine whether the given fulfillment and condition match.
bool validate(Fulfillment const &f, Condition const &c, Slice m)
Verify if the given message satisfies the fulfillment.
bool operator==(Condition const &lhs, Condition const &rhs)
Definition Condition.h:89
static std::unique_ptr< Fulfillment > deserialize(Slice s, std::error_code &ec)
Load a fulfillment from its binary form.
virtual Condition condition() const =0
Returns the condition associated with the given fulfillment.
virtual Buffer fingerprint() const =0
Returns the fulfillment's fingerprint:
virtual Type type() const =0
Returns the type of this condition.
virtual bool validate(Slice data) const =0
Validates a fulfillment.
virtual std::uint32_t cost() const =0
Calculates the cost associated with this fulfillment.
static constexpr std::size_t kMaxSerializedFulfillment
The largest binary fulfillment we support.
Definition Fulfillment.h:25