rippled
Loading...
Searching...
No Matches
Rules.h
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2012, 2013 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_LEDGER_RULES_H_INCLUDED
21#define RIPPLE_LEDGER_RULES_H_INCLUDED
22
23#include <xrpl/basics/base_uint.h>
24#include <xrpl/beast/hash/uhash.h>
25#include <xrpl/protocol/STVector256.h>
26
27#include <unordered_set>
28
29namespace ripple {
30
31class DigestAwareReadView;
32
34class Rules
35{
36private:
37 class Impl;
38
39 // Carrying impl by shared_ptr makes Rules comparatively cheap to pass
40 // by value.
42
43public:
44 Rules(Rules const&) = default;
45
46 Rules(Rules&&) = default;
47
48 Rules&
49 operator=(Rules const&) = default;
50
51 Rules&
52 operator=(Rules&&) = default;
53
54 Rules() = delete;
55
62
63private:
64 // Allow a friend function to construct Rules.
65 friend Rules
67 DigestAwareReadView const& ledger,
68 Rules const& current);
69
70 friend Rules
72 DigestAwareReadView const& ledger,
74
75 Rules(
78 STVector256 const& amendments);
79
81 presets() const;
82
83public:
85 bool
86 enabled(uint256 const& feature) const;
87
92 bool
93 operator==(Rules const&) const;
94
95 bool
96 operator!=(Rules const& other) const;
97};
98
101
102void
104
108{
109public:
112 {
113 setCurrentTransactionRules(std::move(r));
114 }
115
117 {
119 }
120
125
126private:
128};
129
130} // namespace ripple
131#endif
RAII class to set and restore the current transaction rules.
Definition: Rules.h:108
std::optional< Rules > saved_
Definition: Rules.h:127
CurrentTransactionRulesGuard(CurrentTransactionRulesGuard const &)=delete
CurrentTransactionRulesGuard & operator=(CurrentTransactionRulesGuard const &)=delete
ReadView that associates keys with digests.
Definition: ReadView.h:259
Rules controlling protocol behavior.
Definition: Rules.h:35
Rules(Rules const &)=default
std::shared_ptr< Impl const > impl_
Definition: Rules.h:41
bool enabled(uint256 const &feature) const
Returns true if a feature is enabled.
Definition: Rules.cpp:122
bool operator!=(Rules const &other) const
Definition: Rules.cpp:152
friend Rules makeRulesGivenLedger(DigestAwareReadView const &ledger, Rules const &current)
Definition: ReadView.cpp:69
bool operator==(Rules const &) const
Returns true if two rule sets are identical.
Definition: Rules.cpp:141
Rules & operator=(Rules &&)=default
Rules & operator=(Rules const &)=default
Rules(Rules &&)=default
std::unordered_set< uint256, beast::uhash<> > const & presets() const
Definition: Rules.cpp:116
Rules()=delete
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
void setCurrentTransactionRules(std::optional< Rules > r)
Definition: Rules.cpp:45
@ current
This was a new validation and was added.
static Hasher::result_type digest(void const *data, std::size_t size) noexcept
Definition: tokens.cpp:152
std::optional< Rules > const & getCurrentTransactionRules()
Definition: Rules.cpp:39