BitShares-Core  7.0.2
BitShares blockchain node software and command-line wallet 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,
40  protocol_ids, custom_authority_object_type>
41  {
44  mutable optional<restriction_predicate_function> predicate_cache;
45 
46  public:
47  account_id_type account;
48  bool enabled;
49  time_point_sec valid_from;
50  time_point_sec valid_to;
53  flat_map<uint16_t, restriction> restrictions;
54  uint16_t restriction_counter = 0;
55 
57  bool is_valid(time_point_sec now) const { return enabled && now >= valid_from && now < valid_to; }
58 
60  vector<restriction> get_restrictions() const {
61  vector<restriction> rs;
63  std::back_inserter(rs), [](auto i) { return i.second; });
64  return rs;
65  }
68  if (!predicate_cache.valid())
70 
71  return *predicate_cache;
72  }
74  void update_predicate_cache() const {
76  }
78  void clear_predicate_cache() { predicate_cache.reset(); }
79  };
80 
81  struct by_account_custom;
82  struct by_expiration;
83 
87  typedef multi_index_container<
89  indexed_by<
90  ordered_unique<tag<by_id>, member<object, object_id_type, &object::id>>,
91  ordered_unique<tag<by_account_custom>,
92  composite_key<custom_authority_object,
93  member<custom_authority_object, account_id_type, &custom_authority_object::account>,
94  member<custom_authority_object, unsigned_int, &custom_authority_object::operation_type>,
95  member<custom_authority_object, bool, &custom_authority_object::enabled>,
96  member<object, object_id_type, &object::id>
97  >>,
98  ordered_unique<tag<by_expiration>,
99  composite_key<custom_authority_object,
100  member<custom_authority_object, time_point_sec, &custom_authority_object::valid_to>,
101  member<object, object_id_type, &object::id>
102  >
103  >
104  >
106 
111 
112 } } // graphene::chain
113 
115 
117 
graphene::protocol::get_restriction_predicate
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
Definition: restriction_predicate.cpp:32
graphene::chain::custom_authority_object::clear_predicate_cache
void clear_predicate_cache()
Clear the cache of the predicate function.
Definition: custom_authority_object.hpp:78
graphene::chain::custom_authority_multi_index_type
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
Definition: custom_authority_object.hpp:82
FC_REFLECT_TYPENAME
FC_REFLECT_TYPENAME(fc::log_message)
generic_index.hpp
MAP_OBJECT_ID_TO_TYPE
#define MAP_OBJECT_ID_TO_TYPE(OBJECT)
Definition: object_id.hpp:93
graphene::chain::custom_authority_object
Tracks account custom authorities.
Definition: custom_authority_object.hpp:39
graphene::chain::custom_authority_object::account
account_id_type account
Definition: custom_authority_object.hpp:47
graphene::db::abstract_object
Definition: object.hpp:107
graphene::chain::custom_authority_object::enabled
bool enabled
Definition: custom_authority_object.hpp:48
graphene::chain::custom_authority_object::operation_type
unsigned_int operation_type
Definition: custom_authority_object.hpp:51
graphene::chain::custom_authority_object::valid_from
time_point_sec valid_from
Definition: custom_authority_object.hpp:49
fc::unsigned_int
Definition: varint.hpp:6
graphene::chain::custom_authority_object::update_predicate_cache
void update_predicate_cache() const
Regenerate predicate function and update predicate cache.
Definition: custom_authority_object.hpp:74
graphene::chain::by_expiration
Definition: proposal_object.hpp:86
authority.hpp
GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION
#define GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION(type)
Definition: types.hpp:85
graphene::protocol::restriction_predicate_function
std::function< predicate_result(const operation &)> restriction_predicate_function
A restriction predicate is a function accepting an operation and returning a predicate_result.
Definition: restriction_predicate.hpp:62
graphene::chain::custom_authority_object::restriction_counter
uint16_t restriction_counter
Definition: custom_authority_object.hpp:54
fc::typelist::transform
typename impl::transform< List, Transformer >::type transform
Transform elements of a typelist.
Definition: typelist.hpp:170
graphene::chain::custom_authority_object::restrictions
flat_map< uint16_t, restriction > restrictions
Definition: custom_authority_object.hpp:53
graphene::chain::custom_authority_object::get_predicate
restriction_predicate_function get_predicate() const
Get predicate, from cache if possible, and update cache if not (modifies const object!...
Definition: custom_authority_object.hpp:67
custom_authority.hpp
types.hpp
graphene::db::generic_index
Definition: generic_index.hpp:43
graphene::chain::custom_authority_object::get_restrictions
vector< restriction > get_restrictions() const
Get the restrictions as a vector rather than a map.
Definition: custom_authority_object.hpp:60
restriction_predicate.hpp
graphene::protocol::authority
Identifies a weighted set of keys and accounts that must approve operations.
Definition: authority.hpp:34
graphene::chain::custom_authority_object::auth
authority auth
Definition: custom_authority_object.hpp:52
graphene::chain::custom_authority_object::valid_to
time_point_sec valid_to
Definition: custom_authority_object.hpp:50
graphene
Definition: api.cpp:48
graphene::chain::custom_authority_object::is_valid
bool is_valid(time_point_sec now) const
Check whether the custom authority is valid.
Definition: custom_authority_object.hpp:57