BitShares-Core  4.0.0
BitShares blockchain implementation and command-line interface software
custom_authority_object.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019 Contributors.
3  *
4  * The MIT License
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  */
24 #pragma once
29 #include <graphene/chain/types.hpp>
30 #include <boost/multi_index/composite_key.hpp>
31 
32 namespace graphene { namespace chain {
33 
39  class custom_authority_object : public abstract_object<custom_authority_object> {
42  mutable optional<restriction_predicate_function> predicate_cache;
43 
44  public:
45  static const uint8_t space_id = protocol_ids;
46  static const uint8_t type_id = custom_authority_object_type;
47 
48  account_id_type account;
49  bool enabled;
50  time_point_sec valid_from;
51  time_point_sec valid_to;
54  flat_map<uint16_t, restriction> restrictions;
55  uint16_t restriction_counter = 0;
56 
58  bool is_valid(time_point_sec now) const { return enabled && now >= valid_from && now < valid_to; }
59 
61  vector<restriction> get_restrictions() const {
62  vector<restriction> rs;
63  std::transform(restrictions.begin(), restrictions.end(),
64  std::back_inserter(rs), [](auto i) { return i.second; });
65  return rs;
66  }
69  if (!predicate_cache.valid())
71 
72  return *predicate_cache;
73  }
75  void update_predicate_cache() const {
76  predicate_cache = get_restriction_predicate(get_restrictions(), operation_type);
77  }
79  void clear_predicate_cache() { predicate_cache.reset(); }
80  };
81 
82  struct by_account_custom;
83  struct by_expiration;
84 
88  typedef multi_index_container<
90  indexed_by<
91  ordered_unique<tag<by_id>, member<object, object_id_type, &object::id>>,
92  ordered_unique<tag<by_account_custom>,
93  composite_key<custom_authority_object,
94  member<custom_authority_object, account_id_type, &custom_authority_object::account>,
95  member<custom_authority_object, unsigned_int, &custom_authority_object::operation_type>,
96  member<custom_authority_object, bool, &custom_authority_object::enabled>,
97  member<object, object_id_type, &object::id>
98  >>,
99  ordered_unique<tag<by_expiration>,
100  composite_key<custom_authority_object,
101  member<custom_authority_object, time_point_sec, &custom_authority_object::valid_to>,
102  member<object, object_id_type, &object::id>
103  >
104  >
105  >
107 
112 
113 } } // graphene::chain
114 
116 
118 
Identifies a weighted set of keys and accounts that must approve operations.
Definition: authority.hpp:34
void update_predicate_cache() const
Regenerate predicate function and update predicate cache.
Definition: api.cpp:56
restriction_predicate_function get_predicate() const
Get predicate, from cache if possible, and update cache if not (modifies const object!) ...
restriction_predicate_function get_restriction_predicate(vector< restriction > rs, operation::tag_type op_type)
get_restriction_predicate Get a predicate function for the supplied restriction
#define MAP_OBJECT_ID_TO_TYPE(OBJECT)
Definition: object_id.hpp:98
void clear_predicate_cache()
Clear the cache of the predicate function.
Tracks account custom authorities.
bool is_valid(time_point_sec now) const
Check whether the custom authority is valid.
FC_REFLECT_TYPENAME(fc::log_message)
#define GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION(type)
Definition: types.hpp:73
std::function< predicate_result(const operation &)> restriction_predicate_function
A restriction predicate is a function accepting an operation and returning a predicate_result.
Use the Curiously Recurring Template Pattern to automatically add the ability to clone, serialize, and move objects polymorphically.
Definition: object.hpp:90
vector< restriction > get_restrictions() const
Get the restrictions as a vector rather than a map.
flat_map< uint16_t, restriction > restrictions
multi_index_container< custom_authority_object, indexed_by< ordered_unique< tag< by_id >, member< object, object_id_type,&object::id > >, ordered_unique< tag< by_account_custom >, composite_key< custom_authority_object, member< custom_authority_object, account_id_type,&custom_authority_object::account >, member< custom_authority_object, unsigned_int,&custom_authority_object::operation_type >, member< custom_authority_object, bool,&custom_authority_object::enabled >, member< object, object_id_type,&object::id > > >, ordered_unique< tag< by_expiration >, composite_key< custom_authority_object, member< custom_authority_object, time_point_sec,&custom_authority_object::valid_to >, member< object, object_id_type,&object::id > > > > > custom_authority_multi_index_type
typename impl::transform< List, Transformer >::type transform
Transform elements of a typelist.
Definition: typelist.hpp:170