Skip to content

Commit 7c3bdb2

Browse files
BSIP 40: Add database object
1 parent 91bbacc commit 7c3bdb2

File tree

6 files changed

+121
-22
lines changed

6 files changed

+121
-22
lines changed

libraries/chain/db_init.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
#include <graphene/chain/witness_schedule_object.hpp>
4848
#include <graphene/chain/worker_object.hpp>
4949
#include <graphene/chain/htlc_object.hpp>
50+
#include <graphene/chain/custom_authority_object.hpp>
5051

5152
#include <graphene/chain/account_evaluator.hpp>
5253
#include <graphene/chain/asset_evaluator.hpp>
@@ -128,6 +129,8 @@ const uint8_t worker_object::type_id;
128129
const uint8_t htlc_object::space_id;
129130
const uint8_t htlc_object::type_id;
130131

132+
const uint8_t custom_authority_object::space_id;
133+
const uint8_t custom_authority_object::type_id;
131134

132135
void database::initialize_evaluators()
133136
{
@@ -208,6 +211,7 @@ void database::initialize_indexes()
208211
add_index< primary_index<balance_index> >();
209212
add_index< primary_index<blinded_balance_index> >();
210213
add_index< primary_index< htlc_index> >();
214+
add_index< primary_index< custom_authority_index> >();
211215

212216
//Implementation object indexes
213217
add_index< primary_index<transaction_index > >();

libraries/chain/db_notify.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <graphene/chain/operation_history_object.hpp>
1717
#include <graphene/chain/vesting_balance_object.hpp>
1818
#include <graphene/chain/transaction_history_object.hpp>
19+
#include <graphene/chain/custom_authority_object.hpp>
1920
#include <graphene/chain/impacted.hpp>
2021

2122
using namespace fc;
@@ -387,6 +388,11 @@ void get_relevant_accounts( const object* obj, flat_set<account_id_type>& accoun
387388
accounts.insert( htlc_obj->transfer.from );
388389
accounts.insert( htlc_obj->transfer.to );
389390
break;
391+
} case custom_authority_object_type:{
392+
const auto* cust_auth_obj = dynamic_cast<const custom_authority_object*>( obj );
393+
FC_ASSERT( cust_auth_obj != nullptr );
394+
accounts.insert( cust_auth_obj->account );
395+
add_authority_accounts( accounts, cust_auth_obj->auth );
390396
}
391397
}
392398
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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
25+
#include <graphene/protocol/authority.hpp>
26+
#include <graphene/protocol/custom_authority.hpp>
27+
#include <graphene/protocol/restriction_predicate.hpp>
28+
#include <graphene/db/generic_index.hpp>
29+
#include <graphene/chain/types.hpp>
30+
#include <boost/multi_index/composite_key.hpp>
31+
32+
namespace graphene { namespace chain {
33+
34+
/**
35+
* @brief Tracks account custom authorities
36+
* @ingroup object
37+
*
38+
*/
39+
class custom_authority_object : public abstract_object<custom_authority_object> {
40+
public:
41+
static const uint8_t space_id = protocol_ids;
42+
static const uint8_t type_id = custom_authority_object_type;
43+
44+
account_id_type account;
45+
bool enabled;
46+
time_point_sec valid_from;
47+
time_point_sec valid_to;
48+
unsigned_int operation_type;
49+
authority auth;
50+
vector<restriction> restrictions;
51+
52+
/// Unreflected field to store a cache of the predicate function
53+
optional<restriction_predicate_function> predicate_cache;
54+
};
55+
56+
struct by_account_custom;
57+
58+
/**
59+
* @ingroup object_index
60+
*/
61+
typedef multi_index_container<
62+
custom_authority_object,
63+
indexed_by<
64+
ordered_unique<tag<by_id>, member<object, object_id_type, &object::id>>,
65+
ordered_unique<tag<by_account_custom>,
66+
composite_key<
67+
custom_authority_object,
68+
member<custom_authority_object, account_id_type, &custom_authority_object::account>,
69+
member<object, object_id_type, &object::id>
70+
>
71+
>
72+
>
73+
> custom_authority_multi_index_type;
74+
75+
/**
76+
* @ingroup object_index
77+
*/
78+
using custom_authority_index = generic_index<custom_authority_object, custom_authority_multi_index_type>;
79+
80+
} } // graphene::chain
81+
82+
MAP_OBJECT_ID_TO_TYPE(graphene::chain::custom_authority_object)
83+
84+
FC_REFLECT_TYPENAME(graphene::chain::custom_authority_object)
85+
86+
GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION(graphene::chain::custom_authority_object)

libraries/chain/small_objects.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include <graphene/chain/witness_object.hpp>
4242
#include <graphene/chain/witness_schedule_object.hpp>
4343
#include <graphene/chain/worker_object.hpp>
44+
#include <graphene/chain/custom_authority_object.hpp>
4445

4546
#include <fc/io/raw.hpp>
4647

@@ -189,6 +190,9 @@ FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::worker_object, (graphene::db::o
189190
(url)
190191
)
191192

193+
FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::custom_authority_object, (graphene::db::object),
194+
(account)(enabled)(valid_from)(valid_to)(operation_type)(auth)(restrictions) )
195+
192196
GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::chain::balance_object )
193197
GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::chain::block_summary_object )
194198
GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::chain::budget_record )
@@ -210,3 +214,4 @@ GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::chain::withdraw_permission_
210214
GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::chain::witness_object )
211215
GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::chain::witness_schedule_object )
212216
GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::chain::worker_object )
217+
GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::chain::custom_authority_object )

libraries/protocol/include/graphene/protocol/custom_authority.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018 Abit More, and contributors.
2+
* Copyright (c) 2019 Contributors.
33
*
44
* The MIT License
55
*

libraries/protocol/include/graphene/protocol/restriction.hpp

+19-21
Original file line numberDiff line numberDiff line change
@@ -105,27 +105,25 @@ struct restriction {
105105

106106
} } // graphene::protocol
107107

108-
FC_REFLECT_ENUM( graphene::protocol::restriction::function_type,
109-
(func_eq)
110-
(func_ne)
111-
(func_lt)
112-
(func_le)
113-
(func_gt)
114-
(func_ge)
115-
(func_in)
116-
(func_not_in)
117-
(func_has_all)
118-
(func_has_none)
119-
(func_attr)
120-
(func_logical_or)
121-
(FUNCTION_TYPE_COUNT)
122-
)
108+
FC_REFLECT_ENUM(graphene::protocol::restriction::function_type,
109+
(func_eq)
110+
(func_ne)
111+
(func_lt)
112+
(func_le)
113+
(func_gt)
114+
(func_ge)
115+
(func_in)
116+
(func_not_in)
117+
(func_has_all)
118+
(func_has_none)
119+
(func_attr)
120+
(func_logical_or)
121+
(FUNCTION_TYPE_COUNT))
123122

124-
FC_REFLECT( graphene::protocol::restriction,
125-
(member_name)
126-
(restriction_type)
127-
(argument)
128-
(extensions)
129-
)
123+
FC_REFLECT(graphene::protocol::restriction,
124+
(member_name)
125+
(restriction_type)
126+
(argument)
127+
(extensions))
130128

131129

0 commit comments

Comments
 (0)