@@ -48,15 +48,21 @@ void_result custom_authority_create_evaluator::do_evaluate(const custom_authorit
48
48
bool operation_forked_in = hardfork_visitor (now).visit ((operation::tag_type)op.operation_type .value );
49
49
FC_ASSERT (operation_forked_in, " Cannot create custom authority for operation which is not valid yet" );
50
50
51
+ auto restriction_count = std::for_each (op.restrictions .begin (), op.restrictions .end (), restriction::adder ()).sum ;
52
+ FC_ASSERT (restriction_count <= config->max_custom_authority_restrictions ,
53
+ " Custom authority has more than the maximum number of restrictions" );
54
+
51
55
for (const auto & account_weight_pair : op.auth .account_auths )
52
56
account_weight_pair.first (d);
53
57
54
58
const auto & index = d.get_index_type <custom_authority_index>().indices ().get <by_account_custom>();
55
59
auto range = index .equal_range (op.account );
56
60
FC_ASSERT (std::distance (range.first , range.second ) < config->max_custom_authorities_per_account ,
57
- " Cannot create custom authority for account: account already has maximum number" );
61
+ " Cannot create custom authority: account already has maximum number" );
62
+ range = index .equal_range (boost::make_tuple (op.account , op.operation_type ));
63
+ FC_ASSERT (std::distance (range.first , range.second ) < config->max_custom_authorities_per_account_op ,
64
+ " Cannot create custom authority: account already has maximum number for this operation type" );
58
65
59
- get_restriction_predicate (op.restrictions , op.operation_type );
60
66
return void_result ();
61
67
} FC_CAPTURE_AND_RETHROW ((op)) }
62
68
@@ -74,21 +80,16 @@ object_id_type custom_authority_create_evaluator::do_apply(const custom_authorit
74
80
std::for_each (op.restrictions .begin (), op.restrictions .end (), [&obj](const restriction& r) mutable {
75
81
obj.restrictions .insert (std::make_pair (obj.restriction_counter ++, r));
76
82
});
77
-
78
- // Update the predicate cache
79
- obj.update_predicate_cache ();
80
83
}).id ;
81
84
} FC_CAPTURE_AND_RETHROW ((op)) }
82
85
83
86
void_result custom_authority_update_evaluator::do_evaluate (const custom_authority_update_operation& op)
84
87
{ try {
85
88
const database& d = db ();
86
89
auto now = d.head_block_time ();
87
- FC_ASSERT (HARDFORK_BSIP_40_PASSED (now), " Custom active authorities are not yet enabled" );
88
90
old_object = &op.authority_to_update (d);
89
91
FC_ASSERT (old_object->account == op.account , " Cannot update a different account's custom authority" );
90
92
91
- op.account (d);
92
93
if (op.new_enabled )
93
94
FC_ASSERT (*op.new_enabled != old_object->enabled ,
94
95
" Custom authority update specifies an enabled flag, but flag is not changed" );
@@ -131,6 +132,17 @@ void_result custom_authority_update_evaluator::do_evaluate(const custom_authorit
131
132
" Unable to add restrictions: causes wraparound of restriction IDs" );
132
133
}
133
134
135
+ // Add up the restriction counts for all old restrictions not being removed, and all new ones
136
+ size_t restriction_count = 0 ;
137
+ for (const auto & restriction_pair : old_object->restrictions )
138
+ if (op.restrictions_to_remove .count (restriction_pair.first ) == 0 )
139
+ restriction_count += restriction_pair.second .restriction_count ();
140
+ restriction_count += std::for_each (op.restrictions_to_add .begin (), op.restrictions_to_add .end (),
141
+ restriction::adder ()).sum ;
142
+ // Check restriction count against limit
143
+ FC_ASSERT (restriction_count <= config->max_custom_authority_restrictions ,
144
+ " Cannot update custom authority: updated authority would exceed the maximum number of restrictions" );
145
+
134
146
get_restriction_predicate (op.restrictions_to_add , old_object->operation_type );
135
147
return void_result ();
136
148
} FC_CAPTURE_AND_RETHROW ((op)) }
@@ -152,8 +164,8 @@ void_result custom_authority_update_evaluator::do_apply(const custom_authority_u
152
164
obj.restrictions .insert (std::make_pair (obj.restriction_counter ++, r));
153
165
});
154
166
155
- // Update the predicate cache
156
- obj.update_predicate_cache ();
167
+ // Clear the predicate cache
168
+ obj.clear_predicate_cache ();
157
169
});
158
170
159
171
return void_result ();
@@ -162,9 +174,7 @@ void_result custom_authority_update_evaluator::do_apply(const custom_authority_u
162
174
void_result custom_authority_delete_evaluator::do_evaluate (const custom_authority_delete_operation& op)
163
175
{ try {
164
176
const database& d = db ();
165
- FC_ASSERT (HARDFORK_BSIP_40_PASSED (d.head_block_time ()), " Custom active authorities are not yet enabled" );
166
177
167
- op.account (d);
168
178
old_object = &op.authority_to_delete (d);
169
179
FC_ASSERT (old_object->account == op.account , " Cannot delete a different account's custom authority" );
170
180
0 commit comments