Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
permission_object.hpp
Go to the documentation of this file.
1#pragma once
4
6
7namespace sysio { namespace chain {
8
9 class permission_usage_object : public chainbase::object<permission_usage_object_type, permission_usage_object> {
11
12 id_type id;
13 time_point last_used;
14 };
15
16 struct by_account_permission;
19 indexed_by<
20 ordered_unique<tag<by_id>, member<permission_usage_object, permission_usage_object::id_type, &permission_usage_object::id>>
21 >
22 >;
23
24
25 class permission_object : public chainbase::object<permission_object_type, permission_object> {
27
28 id_type id;
30 id_type parent;
31 account_name owner;
33 time_point last_updated;
34 shared_authority auth;
35
36
46 template <typename Index>
47 bool satisfies(const permission_object& other, const Index& permission_index) const {
48 // If the owners are not the same, this permission cannot satisfy other
49 if( owner != other.owner )
50 return false;
51
52 // If this permission matches other, or is the immediate parent of other, then this permission satisfies other
53 if( id == other.id || id == other.parent )
54 return true;
55
56 // Walk up other's parent tree, seeing if we find this permission. If so, this permission satisfies other
57 const permission_object* parent = &*permission_index.template get<by_id>().find(other.parent);
58 while( parent ) {
59 if( id == parent->parent )
60 return true;
61 if( parent->parent._id == 0 )
62 return false;
63 parent = &*permission_index.template get<by_id>().find(parent->parent);
64 }
65 // This permission is not a parent of other, and so does not satisfy other
66 return false;
67 }
68 };
69
81
82
83 struct by_parent;
84 struct by_owner;
85 struct by_name;
88 indexed_by<
89 ordered_unique<tag<by_id>, member<permission_object, permission_object::id_type, &permission_object::id>>,
90 ordered_unique<tag<by_parent>,
91 composite_key<permission_object,
92 member<permission_object, permission_object::id_type, &permission_object::parent>,
93 member<permission_object, permission_object::id_type, &permission_object::id>
94 >
95 >,
96 ordered_unique<tag<by_owner>,
97 composite_key<permission_object,
98 member<permission_object, account_name, &permission_object::owner>,
99 member<permission_object, permission_name, &permission_object::name>
100 >
101 >,
102 ordered_unique<tag<by_name>,
103 composite_key<permission_object,
104 member<permission_object, permission_name, &permission_object::name>,
105 member<permission_object, permission_object::id_type, &permission_object::id>
106 >
107 >
108 >
109 >;
110
111 namespace config {
112 template<>
113 struct billable_size<permission_object> { // Also counts memory usage of the associated permission_usage_object
114 static const uint64_t overhead = 5 * overhead_per_row_per_index_ram_bytes;
116 };
117 }
118} } // sysio::chain
119
122
123FC_REFLECT(sysio::chain::permission_object, (usage_id)(parent)(owner)(name)(last_updated)(auth))
124FC_REFLECT(sysio::chain::snapshot_permission_object, (parent)(owner)(name)(last_updated)(last_used)(auth))
125
std::string name
#define OBJECT_CTOR(...)
Definition types.hpp:39
#define CHAINBASE_SET_INDEX_TYPE(OBJECT_TYPE, INDEX_TYPE)
boost::multi_index_container< Object, Args..., chainbase::node_allocator< Object > > shared_multi_index_container
constexpr uint64_t billable_size_v
Definition config.hpp:147
chainbase::shared_multi_index_container< permission_object, indexed_by< ordered_unique< tag< by_id >, member< permission_object, permission_object::id_type, &permission_object::id > >, ordered_unique< tag< by_parent >, composite_key< permission_object, member< permission_object, permission_object::id_type, &permission_object::parent >, member< permission_object, permission_object::id_type, &permission_object::id > > >, ordered_unique< tag< by_owner >, composite_key< permission_object, member< permission_object, account_name, &permission_object::owner >, member< permission_object, permission_name, &permission_object::name > > >, ordered_unique< tag< by_name >, composite_key< permission_object, member< permission_object, permission_name, &permission_object::name >, member< permission_object, permission_object::id_type, &permission_object::id > > > > > permission_index
chainbase::shared_multi_index_container< permission_usage_object, indexed_by< ordered_unique< tag< by_id >, member< permission_usage_object, permission_usage_object::id_type, &permission_usage_object::id > > > > permission_usage_index
#define value
Definition pkcs11.h:157
#define FC_REFLECT(TYPE, MEMBERS)
Specializes fc::reflector for TYPE.
Definition reflect.hpp:311
unsigned __int64 uint64_t
Definition stdint.h:136
Immutable except for fc::from_variant.
Definition name.hpp:43
authority auth
authority required to execute this permission
permission_name parent
parent permission
time_point last_updated
the last time this authority was updated
account_name owner
the account this permission belongs to
permission_name name
human-readable name for the permission
time_point last_used
when this permission was last used