|
23 | 23 | */
|
24 | 24 | #include <graphene/protocol/custom_authority.hpp>
|
25 | 25 | #include <graphene/protocol/operations.hpp>
|
| 26 | +#include <graphene/protocol/restriction_predicate.hpp> |
26 | 27 |
|
27 | 28 | namespace graphene { namespace protocol {
|
28 | 29 |
|
29 |
| -share_type custom_authority_create_operation::calculate_fee( const fee_parameters_type& k )const |
30 |
| -{ |
| 30 | +share_type custom_authority_create_operation::calculate_fee(const fee_parameters_type& k)const { |
31 | 31 | share_type core_fee_required = k.basic_fee;
|
32 |
| - |
33 |
| - if( enabled ) |
34 |
| - { |
35 |
| - share_type unit_fee = k.price_per_k_unit; |
36 |
| - unit_fee *= (valid_to - valid_from).to_seconds(); |
37 |
| - unit_fee *= auth.num_auths(); |
38 |
| - uint64_t restriction_units = 0; |
39 |
| - for( const auto& r : restrictions ) |
40 |
| - { |
41 |
| - restriction_units += r.get_units(); |
42 |
| - } |
43 |
| - unit_fee *= restriction_units; |
44 |
| - unit_fee /= 1000; |
45 |
| - core_fee_required += unit_fee; |
46 |
| - } |
47 |
| - |
| 32 | + core_fee_required += k.price_per_byte * (fc::raw::pack_size(restrictions) + fc::raw::pack_size(auth)); |
48 | 33 | return core_fee_required;
|
49 | 34 | }
|
50 | 35 |
|
51 |
| -void custom_authority_create_operation::validate()const |
52 |
| -{ |
53 |
| - FC_ASSERT( fee.amount >= 0, "Fee amount can not be negative" ); |
| 36 | +void custom_authority_create_operation::validate()const { |
| 37 | + FC_ASSERT(fee.amount >= 0, "Fee amount can not be negative"); |
54 | 38 |
|
55 |
| - FC_ASSERT( account != GRAPHENE_TEMP_ACCOUNT |
56 |
| - && account != GRAPHENE_COMMITTEE_ACCOUNT |
57 |
| - && account != GRAPHENE_WITNESS_ACCOUNT |
58 |
| - && account != GRAPHENE_RELAXED_COMMITTEE_ACCOUNT, |
59 |
| - "Can not create custom authority for special accounts" ); |
| 39 | + FC_ASSERT(account != GRAPHENE_TEMP_ACCOUNT |
| 40 | + && account != GRAPHENE_COMMITTEE_ACCOUNT |
| 41 | + && account != GRAPHENE_WITNESS_ACCOUNT |
| 42 | + && account != GRAPHENE_RELAXED_COMMITTEE_ACCOUNT, |
| 43 | + "Can not create custom authority for special accounts"); |
60 | 44 |
|
61 |
| - FC_ASSERT( valid_from < valid_to, "valid_from must be earlier than valid_to" ); |
| 45 | + FC_ASSERT(valid_from < valid_to, "valid_from must be earlier than valid_to"); |
62 | 46 |
|
63 |
| - // Note: when adding new operation with hard fork, need to check more strictly in evaluator |
64 |
| - // TODO add code in evaluator |
65 |
| - FC_ASSERT( operation_type.value < operation::count(), "operation_type is too large" ); |
| 47 | + // Note: The authentication authority can be empty, but it cannot be impossible to satisify. Disable the authority |
| 48 | + // using the `enabled` boolean rather than setting an impossible authority. |
66 | 49 |
|
67 |
| - // Note: allow auths to be empty |
68 |
| - //FC_ASSERT( auth.num_auths() > 0, "Can not set empty auth" ); |
69 |
| - FC_ASSERT( auth.address_auths.size() == 0, "Address auth is not supported" ); |
70 |
| - // Note: allow auths to be impossible |
71 |
| - //FC_ASSERT( !auth.is_impossible(), "cannot use an imposible authority threshold" ); |
| 50 | + FC_ASSERT(auth.address_auths.size() == 0, "Address authorities are not supported"); |
| 51 | + FC_ASSERT(!auth.is_impossible(), "Cannot use an imposible authority threshold"); |
72 | 52 |
|
73 |
| - // Note: allow restrictions to be empty |
74 |
| - for( const auto& r: restrictions ) |
75 |
| - { |
76 |
| - // recursively validate member index and argument type |
77 |
| - r.validate( operation_type ); |
78 |
| - } |
| 53 | + // Validate restrictions by constructing a predicate for them; this throws if restrictions aren't valid |
| 54 | + get_restriction_predicate(restrictions, operation_type); |
79 | 55 | }
|
80 | 56 |
|
81 |
| -share_type custom_authority_update_operation::calculate_fee( const fee_parameters_type& k )const |
82 |
| -{ |
| 57 | +share_type custom_authority_update_operation::calculate_fee(const fee_parameters_type& k)const { |
83 | 58 | share_type core_fee_required = k.basic_fee;
|
84 |
| - |
85 |
| - share_type unit_fee = k.price_per_k_unit; |
86 |
| - unit_fee *= delta_units; |
87 |
| - unit_fee /= 1000; |
88 |
| - |
89 |
| - return core_fee_required + unit_fee; |
| 59 | + core_fee_required += k.price_per_byte * fc::raw::pack_size(restrictions_to_add); |
| 60 | + if (new_auth) |
| 61 | + core_fee_required += k.price_per_byte * fc::raw::pack_size(*new_auth); |
| 62 | + return core_fee_required; |
90 | 63 | }
|
91 | 64 |
|
92 |
| -void custom_authority_update_operation::validate()const |
93 |
| -{ |
94 |
| - FC_ASSERT( fee.amount >= 0, "Fee amount can not be negative" ); |
95 |
| - |
96 |
| - FC_ASSERT( account != GRAPHENE_TEMP_ACCOUNT |
97 |
| - && account != GRAPHENE_COMMITTEE_ACCOUNT |
98 |
| - && account != GRAPHENE_WITNESS_ACCOUNT |
99 |
| - && account != GRAPHENE_RELAXED_COMMITTEE_ACCOUNT, |
100 |
| - "Can not create custom authority for special accounts" ); |
101 |
| -/* |
102 |
| - FC_ASSERT( valid_from < valid_to, "valid_from must be earlier than valid_to" ); |
103 |
| - // Note: when adding new operation with hard fork, need to check more strictly in evaluator |
104 |
| - // TODO add code in evaluator |
105 |
| - FC_ASSERT( operation_type < operation::count(), "operation type too large" ); |
106 |
| - FC_ASSERT( auth.num_auths() > 0, "Can not set empty auth" ); |
107 |
| - FC_ASSERT( auth.address_auths.size() == 0, "Address auth is not supported" ); |
108 |
| - //FC_ASSERT( !auth.is_impossible(), "cannot use an imposible authority threshold" ); |
109 |
| - // Note: allow restrictions to be empty |
110 |
| - for( const auto& r : restrictions ) |
111 |
| - { |
112 |
| - // TODO recursively validate member index and argument type |
113 |
| - r.validate( operation_type ); |
| 65 | +void custom_authority_update_operation::validate()const { |
| 66 | + FC_ASSERT(fee.amount >= 0, "Fee amount can not be negative"); |
| 67 | + |
| 68 | + FC_ASSERT(account != GRAPHENE_TEMP_ACCOUNT |
| 69 | + && account != GRAPHENE_COMMITTEE_ACCOUNT |
| 70 | + && account != GRAPHENE_WITNESS_ACCOUNT |
| 71 | + && account != GRAPHENE_RELAXED_COMMITTEE_ACCOUNT, |
| 72 | + "Can not create custom authority for special accounts"); |
| 73 | + if (new_valid_from && new_valid_to) |
| 74 | + FC_ASSERT(*new_valid_from < new_valid_to, "valid_from must be earlier than valid_to"); |
| 75 | + if (new_auth) { |
| 76 | + FC_ASSERT(!new_auth->is_impossible(), "Cannot use an impossible authority threshold"); |
| 77 | + FC_ASSERT(new_auth->address_auths.size() == 0, "Address auth is not supported"); |
114 | 78 | }
|
115 |
| -*/ |
116 |
| -} |
117 |
| - |
118 |
| -void custom_authority_delete_operation::validate()const |
119 |
| -{ |
120 | 79 | }
|
121 | 80 |
|
122 | 81 | } } // graphene::protocol
|
0 commit comments