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
31bool
32isFeatureEnabled(uint256 const& feature);
33
34class DigestAwareReadView;
35
37class Rules
38{
39private:
40 class Impl;
41
42 // Carrying impl by shared_ptr makes Rules comparatively cheap to pass
43 // by value.
45
46public:
47 Rules(Rules const&) = default;
48
49 Rules(Rules&&) = default;
50
51 Rules&
52 operator=(Rules const&) = default;
53
54 Rules&
55 operator=(Rules&&) = default;
56
57 Rules() = delete;
58
65
66private:
67 // Allow a friend function to construct Rules.
68 friend Rules
70 DigestAwareReadView const& ledger,
71 Rules const& current);
72
73 friend Rules
75 DigestAwareReadView const& ledger,
77
78 Rules(
81 STVector256 const& amendments);
82
84 presets() const;
85
86public:
88 bool
89 enabled(uint256 const& feature) const;
90
95 bool
96 operator==(Rules const&) const;
97
98 bool
99 operator!=(Rules const& other) const;
100};
101
104
105void
107
111{
112public:
115 {
116 setCurrentTransactionRules(std::move(r));
117 }
118
120 {
122 }
123
128
129private:
131};
132
133} // namespace ripple
134#endif
RAII class to set and restore the current transaction rules.
Definition: Rules.h:111
std::optional< Rules > saved_
Definition: Rules.h:130
CurrentTransactionRulesGuard(CurrentTransactionRulesGuard const &)=delete
CurrentTransactionRulesGuard & operator=(CurrentTransactionRulesGuard const &)=delete
ReadView that associates keys with digests.
Definition: ReadView.h:256
Rules controlling protocol behavior.
Definition: Rules.h:38
Rules(Rules const &)=default
std::shared_ptr< Impl const > impl_
Definition: Rules.h:44
bool enabled(uint256 const &feature) const
Returns true if a feature is enabled.
Definition: Rules.cpp:130
bool operator!=(Rules const &other) const
Definition: Rules.cpp:160
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:149
Rules & operator=(Rules &&)=default
Rules & operator=(Rules const &)=default
Rules(Rules &&)=default
std::unordered_set< uint256, beast::uhash<> > const & presets() const
Definition: Rules.cpp:124
Rules()=delete
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
bool isFeatureEnabled(uint256 const &feature)
Definition: Rules.cpp:166
void setCurrentTransactionRules(std::optional< Rules > r)
Definition: Rules.cpp:53
base_uint< 256 > uint256
Definition: base_uint.h:558
@ 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:156
std::optional< Rules > const & getCurrentTransactionRules()
Definition: Rules.cpp:47