rippled
Loading...
Searching...
No Matches
Fulfillment.h
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2016 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#ifndef RIPPLE_CONDITIONS_FULFILLMENT_H
21#define RIPPLE_CONDITIONS_FULFILLMENT_H
22
23#include <xrpld/conditions/Condition.h>
24
25#include <xrpl/basics/Buffer.h>
26#include <xrpl/basics/Slice.h>
27
28namespace ripple {
29namespace cryptoconditions {
30
32{
33public:
41 static constexpr std::size_t maxSerializedFulfillment = 256;
42
55
56public:
57 virtual ~Fulfillment() = default;
58
66 virtual Buffer
67 fingerprint() const = 0;
68
70 virtual Type
71 type() const = 0;
72
74 virtual bool
75 validate(Slice data) const = 0;
76
83 virtual std::uint32_t
84 cost() const = 0;
85
92 virtual Condition
93 condition() const = 0;
94};
95
96inline bool
97operator==(Fulfillment const& lhs, Fulfillment const& rhs)
98{
99 // FIXME: for compound conditions, need to also check subtypes
100 return lhs.type() == rhs.type() && lhs.cost() == rhs.cost() &&
101 lhs.fingerprint() == rhs.fingerprint();
102}
103
104inline bool
105operator!=(Fulfillment const& lhs, Fulfillment const& rhs)
106{
107 return !(lhs == rhs);
108}
109
111bool
112match(Fulfillment const& f, Condition const& c);
113
124bool
125validate(Fulfillment const& f, Condition const& c, Slice m);
126
140bool
141validate(Fulfillment const& f, Condition const& c);
142
143} // namespace cryptoconditions
144} // namespace ripple
145
146#endif
Like std::vector<char> but better.
Definition Buffer.h:36
An immutable linear range of bytes.
Definition Slice.h:46
bool operator==(Condition const &lhs, Condition const &rhs)
Definition Condition.h:102
bool operator!=(Condition const &lhs, Condition const &rhs)
Definition Condition.h:109
bool validate(Fulfillment const &f, Condition const &c, Slice m)
Verify if the given message satisfies the fulfillment.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25
static std::unique_ptr< Fulfillment > deserialize(Slice s, std::error_code &ec)
Load a fulfillment from its binary form.
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 maxSerializedFulfillment
The largest binary fulfillment we support.
Definition Fulfillment.h:41
virtual Condition condition() const =0
Returns the condition associated with the given fulfillment.
virtual Buffer fingerprint() const =0
Returns the fulfillment's fingerprint: