BitShares-Core  5.0.0
BitShares blockchain implementation and command-line interface software
custom_authority.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018 Abit More, and 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  */
27 
28 #include <fc/io/raw.hpp>
29 
30 namespace graphene { namespace protocol {
31 
33  share_type core_fee_required = k.basic_fee;
34  // Note: practically the `*` won't cause an integer overflow, because k.price_per_byte is 32 bit
35  // and the results of pack_size() won't be too big
37  return core_fee_required;
38 }
39 
41  FC_ASSERT(fee.amount >= 0, "Fee amount can not be negative");
42 
47  "Can not create custom authority for special accounts");
48 
49  FC_ASSERT(valid_from < valid_to, "valid_from must be earlier than valid_to");
50 
51  // Note: The authentication authority can be empty, but it cannot be impossible to satisify. Disable the authority
52  // using the `enabled` boolean rather than setting an impossible authority.
53 
54  FC_ASSERT(auth.address_auths.size() == 0, "Address authorities are not supported");
55  FC_ASSERT(!auth.is_impossible(), "Cannot use an imposible authority threshold");
56 
57  // Validate restrictions by constructing a predicate for them; this throws if restrictions aren't valid
59 }
60 
62  share_type core_fee_required = k.basic_fee;
63  // Note: practically the `*` won't cause an integer overflow, because k.price_per_byte is 32 bit
64  // and the results of pack_size() won't be too big
65  core_fee_required += k.price_per_byte * fc::raw::pack_size(restrictions_to_add);
66  if (new_auth)
67  core_fee_required += k.price_per_byte * fc::raw::pack_size(*new_auth);
68  return core_fee_required;
69 }
70 
72  FC_ASSERT(fee.amount >= 0, "Fee amount can not be negative");
73 
78  "Can not create custom authority for special accounts");
79  if (new_valid_from && new_valid_to)
80  FC_ASSERT(*new_valid_from < *new_valid_to, "valid_from must be earlier than valid_to");
81  if (new_auth) {
82  FC_ASSERT(!new_auth->is_impossible(), "Cannot use an impossible authority threshold");
83  FC_ASSERT(new_auth->address_auths.size() == 0, "Address auth is not supported");
84  }
85  FC_ASSERT( new_enabled.valid() || new_valid_from.valid() || new_valid_to.valid() || new_auth.valid()
86  || !restrictions_to_remove.empty() || !restrictions_to_add.empty(),
87  "Must update something" );
88 }
89 
91  FC_ASSERT(fee.amount >= 0, "Fee amount can not be negative");
92 
97  "Can not delete custom authority for special accounts");
98 }
99 
100 } } // graphene::protocol
#define GRAPHENE_TEMP_ACCOUNT
Represents the canonical account with WILDCARD authority (anybody can access funds in temp account) ...
Definition: config.hpp:133
vector< restriction > restrictions
Restrictions on operations this custom authority can authenticate.
Definition: api.cpp:56
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
flat_map< address, weight_type > address_auths
Definition: authority.hpp:123
share_type calculate_fee(const fee_parameters_type &k) const
share_type calculate_fee(const fee_parameters_type &k) const
size_t pack_size(const T &v)
Definition: raw.hpp:757
time_point_sec valid_to
Expiration date for custom authority.
time_point_sec valid_from
Date when custom authority becomes active.
#define GRAPHENE_COMMITTEE_ACCOUNT
Definition: config.hpp:125
#define FC_ASSERT(TEST,...)
Checks a condition and throws an assert_exception if the test is FALSE.
Definition: exception.hpp:345
account_id_type account
Account which is setting the custom authority; also pays the fee.
unsigned_int operation_type
Tag of the operation this custom authority can authorize.
#define GRAPHENE_RELAXED_COMMITTEE_ACCOUNT
Represents the current committee members.
Definition: config.hpp:129
authority auth
Authentication requirements for the custom authority.
#define GRAPHENE_WITNESS_ACCOUNT
Represents the current witnesses.
Definition: config.hpp:127