rippled
Rules.cpp
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 #include <ripple/protocol/Feature.h>
21 #include <ripple/protocol/Rules.h>
22 
23 namespace ripple {
24 
26 {
27 private:
31 
32 public:
34  : presets_(presets)
35  {
36  }
37 
41  STVector256 const& amendments)
43  {
44  set_.reserve(amendments.size());
45  set_.insert(amendments.begin(), amendments.end());
46  }
47 
49  presets() const
50  {
51  return presets_;
52  }
53 
54  bool
55  enabled(uint256 const& feature) const
56  {
57  if (presets_.count(feature) > 0)
58  return true;
59  return set_.count(feature) > 0;
60  }
61 
62  bool
63  operator==(Impl const& other) const
64  {
65  if (!digest_ && !other.digest_)
66  return true;
67  if (!digest_ || !other.digest_)
68  return false;
69  assert(presets_ == other.presets_);
70  return *digest_ == *other.digest_;
71  }
72 };
73 
75  : impl_(std::make_shared<Impl>(presets))
76 {
77 }
78 
80  std::unordered_set<uint256, beast::uhash<>> const& presets,
82  STVector256 const& amendments)
83  : impl_(std::make_shared<Impl>(presets, digest, amendments))
84 {
85 }
86 
89 {
90  return impl_->presets();
91 }
92 
93 bool
94 Rules::enabled(uint256 const& feature) const
95 {
96  assert(impl_);
97 
98  // The functionality of the "NonFungibleTokensV1_1" amendment is
99  // precisely the functionality of the following three amendments
100  // so if their status is ever queried individually, we inject an
101  // extra check here to simplify the checking elsewhere.
102  if (feature == featureNonFungibleTokensV1 ||
103  feature == fixNFTokenNegOffer || feature == fixNFTokenDirV1)
104  {
105  if (impl_->enabled(featureNonFungibleTokensV1_1))
106  return true;
107  }
108 
109  return impl_->enabled(feature);
110 }
111 
112 bool
113 Rules::operator==(Rules const& other) const
114 {
115  assert(impl_ && other.impl_);
116  if (impl_.get() == other.impl_.get())
117  return true;
118  return *impl_ == *other.impl_;
119 }
120 
121 bool
122 Rules::operator!=(Rules const& other) const
123 {
124  return !(*this == other);
125 }
126 } // namespace ripple
ripple::fixNFTokenNegOffer
const uint256 fixNFTokenNegOffer
ripple::Rules::presets
std::unordered_set< uint256, beast::uhash<> > const & presets() const
Definition: Rules.cpp:88
ripple::Rules::enabled
bool enabled(uint256 const &feature) const
Returns true if a feature is enabled.
Definition: Rules.cpp:94
ripple::Rules::Rules
Rules()=delete
ripple::Rules::impl_
std::shared_ptr< Impl const > impl_
Definition: Rules.h:36
std::unordered_set
STL class.
ripple::Rules::Impl::Impl
Impl(std::unordered_set< uint256, beast::uhash<>> const &presets)
Definition: Rules.cpp:33
ripple::Rules::Impl::presets_
std::unordered_set< uint256, beast::uhash<> > const & presets_
Definition: Rules.cpp:30
ripple::Rules::Impl::Impl
Impl(std::unordered_set< uint256, beast::uhash<>> const &presets, std::optional< uint256 > const &digest, STVector256 const &amendments)
Definition: Rules.cpp:38
ripple::Rules::operator!=
bool operator!=(Rules const &other) const
Definition: Rules.cpp:122
ripple::digest
static Hasher::result_type digest(void const *data, std::size_t size) noexcept
Definition: tokens.cpp:47
ripple::base_uint< 256 >
ripple::Rules::Impl
Definition: Rules.cpp:25
ripple::fixNFTokenDirV1
const uint256 fixNFTokenDirV1
ripple::Rules::operator==
bool operator==(Rules const &) const
Returns true if two rule sets are identical.
Definition: Rules.cpp:113
ripple::Rules::Impl::presets
std::unordered_set< uint256, beast::uhash<> > const & presets() const
Definition: Rules.cpp:49
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::featureNonFungibleTokensV1
const uint256 featureNonFungibleTokensV1
ripple::Rules::Impl::enabled
bool enabled(uint256 const &feature) const
Definition: Rules.cpp:55
ripple::Rules::Impl::set_
std::unordered_set< uint256, hardened_hash<> > set_
Definition: Rules.cpp:28
std
STL namespace.
ripple::featureNonFungibleTokensV1_1
const uint256 featureNonFungibleTokensV1_1
ripple::STVector256
Definition: STVector256.h:29
ripple::Rules
Rules controlling protocol behavior.
Definition: Rules.h:33
std::optional
beast::uhash<>
ripple::Rules::Impl::digest_
std::optional< uint256 > digest_
Definition: Rules.cpp:29
ripple::Rules::Impl::operator==
bool operator==(Impl const &other) const
Definition: Rules.cpp:63