BitShares-Core  7.0.2
BitShares blockchain node software and command-line wallet 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");
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  }
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
graphene::protocol::custom_authority_create_operation::valid_to
time_point_sec valid_to
Expiration date for custom authority.
Definition: custom_authority.hpp:51
graphene::protocol::get_restriction_predicate
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
Definition: restriction_predicate.cpp:32
GRAPHENE_RELAXED_COMMITTEE_ACCOUNT
#define GRAPHENE_RELAXED_COMMITTEE_ACCOUNT
Represents the current committee members.
Definition: config.hpp:144
graphene::protocol::custom_authority_create_operation::fee_params_t::price_per_byte
uint32_t price_per_byte
Definition: custom_authority.hpp:39
graphene::protocol::custom_authority_create_operation::account
account_id_type account
Account which is setting the custom authority; also pays the fee.
Definition: custom_authority.hpp:45
graphene::protocol::custom_authority_create_operation::operation_type
unsigned_int operation_type
Tag of the operation this custom authority can authorize.
Definition: custom_authority.hpp:53
graphene::protocol::authority::address_auths
flat_map< address, weight_type > address_auths
Definition: authority.hpp:123
graphene::protocol::custom_authority_update_operation::new_enabled
optional< bool > new_enabled
Change to whether the custom authority is enabled or not.
Definition: custom_authority.hpp:83
graphene::protocol::custom_authority_update_operation::calculate_fee
share_type calculate_fee(const fee_params_t &k) const
Definition: custom_authority.cpp:61
graphene::protocol::custom_authority_update_operation::fee_params_t::basic_fee
uint64_t basic_fee
Definition: custom_authority.hpp:72
GRAPHENE_TEMP_ACCOUNT
#define GRAPHENE_TEMP_ACCOUNT
Represents the canonical account with WILDCARD authority (anybody can access funds in temp account)
Definition: config.hpp:148
graphene::protocol::custom_authority_delete_operation::validate
void validate() const
Definition: custom_authority.cpp:90
graphene::protocol::custom_authority_update_operation::new_valid_to
optional< time_point_sec > new_valid_to
Change to the custom authority expiration date.
Definition: custom_authority.hpp:87
graphene::protocol::custom_authority_update_operation::restrictions_to_remove
flat_set< uint16_t > restrictions_to_remove
Set of IDs of restrictions to remove.
Definition: custom_authority.hpp:91
graphene::protocol::custom_authority_create_operation::fee_params_t
Definition: custom_authority.hpp:37
graphene::protocol::custom_authority_create_operation::auth
authority auth
Authentication requirements for the custom authority.
Definition: custom_authority.hpp:55
graphene::protocol::custom_authority_update_operation::fee_params_t::price_per_byte
uint32_t price_per_byte
Definition: custom_authority.hpp:73
graphene::protocol::custom_authority_create_operation::valid_from
time_point_sec valid_from
Date when custom authority becomes active.
Definition: custom_authority.hpp:49
graphene::protocol::custom_authority_update_operation::restrictions_to_add
vector< restriction > restrictions_to_add
Vector of new restrictions.
Definition: custom_authority.hpp:93
operations.hpp
graphene::protocol::custom_authority_update_operation::validate
void validate() const
Definition: custom_authority.cpp:71
fc::optional::valid
bool valid() const
Definition: optional.hpp:186
graphene::protocol::custom_authority_update_operation::new_auth
optional< authority > new_auth
Change to the authentication for the custom authority.
Definition: custom_authority.hpp:89
graphene::protocol::custom_authority_create_operation::restrictions
vector< restriction > restrictions
Restrictions on operations this custom authority can authenticate.
Definition: custom_authority.hpp:57
graphene::protocol::custom_authority_create_operation::validate
void validate() const
Definition: custom_authority.cpp:40
fc::raw::pack_size
size_t pack_size(const T &v)
Definition: raw.hpp:757
graphene::protocol::custom_authority_delete_operation::fee
asset fee
Operation fee.
Definition: custom_authority.hpp:111
graphene::protocol::custom_authority_create_operation::fee
asset fee
Operation fee.
Definition: custom_authority.hpp:43
graphene::protocol::authority::is_impossible
bool is_impossible() const
Definition: authority.hpp:64
GRAPHENE_COMMITTEE_ACCOUNT
#define GRAPHENE_COMMITTEE_ACCOUNT
Definition: config.hpp:140
FC_ASSERT
#define FC_ASSERT(TEST,...)
Checks a condition and throws an assert_exception if the test is FALSE.
Definition: exception.hpp:345
GRAPHENE_WITNESS_ACCOUNT
#define GRAPHENE_WITNESS_ACCOUNT
Represents the current witnesses.
Definition: config.hpp:142
graphene::protocol::asset::amount
share_type amount
Definition: asset.hpp:36
graphene::protocol::custom_authority_update_operation::fee
asset fee
Operation fee.
Definition: custom_authority.hpp:77
graphene::protocol::custom_authority_create_operation::calculate_fee
share_type calculate_fee(const fee_params_t &k) const
Definition: custom_authority.cpp:32
custom_authority.hpp
restriction_predicate.hpp
graphene::protocol::custom_authority_update_operation::account
account_id_type account
Account which owns the custom authority to update; also pays the fee.
Definition: custom_authority.hpp:79
graphene::protocol::custom_authority_delete_operation::account
account_id_type account
Account which owns the custom authority to update; also pays the fee.
Definition: custom_authority.hpp:113
graphene::protocol::custom_authority_update_operation::new_valid_from
optional< time_point_sec > new_valid_from
Change to the custom authority begin date.
Definition: custom_authority.hpp:85
graphene::protocol::custom_authority_create_operation::fee_params_t::basic_fee
uint64_t basic_fee
Definition: custom_authority.hpp:38
graphene
Definition: api.cpp:48
graphene::protocol::custom_authority_update_operation::fee_params_t
Definition: custom_authority.hpp:71
raw.hpp
fc::safe
Definition: safe.hpp:26