BitShares-Core  7.0.2
BitShares blockchain node software and command-line wallet software
operations.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 Cryptonomex, Inc., 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  */
24 
27 
28 #include <fc/io/raw.hpp>
29 #include <fc/uint128.hpp>
30 
31 namespace graphene { namespace protocol {
32 
33 uint64_t base_operation::calculate_data_fee( uint64_t bytes, uint64_t price_per_kbyte )
34 {
35  auto result = (fc::uint128_t(bytes) * price_per_kbyte) / 1024;
37  return static_cast<uint64_t>(result);
38 }
39 
41 {
42  validate();
44 }
45 
47 {
48  FC_ASSERT( fee == asset() );
50 }
51 
56 {
57  typedef void result_type;
58  template<typename T>
59  void operator()( const T& v )const { v.validate(); }
60 };
61 
63 {
64  using result_type = void;
65 
66  flat_set<account_id_type>& active;
67  flat_set<account_id_type>& owner;
68  vector<authority>& other;
70 
71 
72  operation_get_required_auth( flat_set<account_id_type>& a,
73  flat_set<account_id_type>& own,
74  vector<authority>& oth,
75  bool ignore_custom_operation_required_auths )
76  : active( a ), owner( own ), other( oth ),
77  ignore_custom_op_reqd_auths( ignore_custom_operation_required_auths )
78  {}
79 
80  template<typename T>
81  void operator()( const T& v ) const {
82  active.insert( v.fee_payer() );
83  v.get_required_active_authorities( active );
84  v.get_required_owner_authorities( owner );
85  v.get_required_authorities( other );
86  }
87 
88  void operator()( const custom_operation& op ) const {
89  active.insert( op.fee_payer() );
94  }
95  }
96 };
97 
98 void operation_validate( const operation& op )
99 {
100  op.visit( operation_validator() );
101 }
102 
104  flat_set<account_id_type>& active,
105  flat_set<account_id_type>& owner,
106  vector<authority>& other,
107  bool ignore_custom_operation_required_auths )
108 {
109  op.visit( operation_get_required_auth( active, owner, other, ignore_custom_operation_required_auths ) );
110 }
111 
112 } } // namespace graphene::protocol
113 
117 
GRAPHENE_MAX_SHARE_SUPPLY
constexpr int64_t GRAPHENE_MAX_SHARE_SUPPLY(1000000000000000LL)
graphene::protocol::operation_validator
Used to validate operations in a polymorphic manner.
Definition: operations.cpp:55
uint128.hpp
graphene::protocol::custom_operation
provides a generic way to add higher level protocols on top of witness consensus
Definition: custom.hpp:38
graphene::protocol::operation_get_required_auth::active
flat_set< account_id_type > & active
Definition: operations.cpp:66
fc::static_variant< transfer_operation, limit_order_create_operation, limit_order_cancel_operation, call_order_update_operation, fill_order_operation, account_create_operation, account_update_operation, account_whitelist_operation, account_upgrade_operation, account_transfer_operation, asset_create_operation, asset_update_operation, asset_update_bitasset_operation, asset_update_feed_producers_operation, asset_issue_operation, asset_reserve_operation, asset_fund_fee_pool_operation, asset_settle_operation, asset_global_settle_operation, asset_publish_feed_operation, witness_create_operation, witness_update_operation, proposal_create_operation, proposal_update_operation, proposal_delete_operation, withdraw_permission_create_operation, withdraw_permission_update_operation, withdraw_permission_claim_operation, withdraw_permission_delete_operation, committee_member_create_operation, committee_member_update_operation, committee_member_update_global_parameters_operation, vesting_balance_create_operation, vesting_balance_withdraw_operation, worker_create_operation, custom_operation, assert_operation, balance_claim_operation, override_transfer_operation, transfer_to_blind_operation, blind_transfer_operation, transfer_from_blind_operation, asset_settle_cancel_operation, asset_claim_fees_operation, fba_distribute_operation, bid_collateral_operation, execute_bid_operation, asset_claim_pool_operation, asset_update_issuer_operation, htlc_create_operation, htlc_redeem_operation, htlc_redeemed_operation, htlc_extend_operation, htlc_refund_operation, custom_authority_create_operation, custom_authority_update_operation, custom_authority_delete_operation, ticket_create_operation, ticket_update_operation, liquidity_pool_create_operation, liquidity_pool_delete_operation, liquidity_pool_deposit_operation, liquidity_pool_withdraw_operation, liquidity_pool_exchange_operation, samet_fund_create_operation, samet_fund_delete_operation, samet_fund_update_operation, samet_fund_borrow_operation, samet_fund_repay_operation, credit_offer_create_operation, credit_offer_delete_operation, credit_offer_update_operation, credit_offer_accept_operation, credit_deal_repay_operation, credit_deal_expired_operation, liquidity_pool_update_operation, credit_deal_update_operation, limit_order_update_operation >
graphene::protocol::balance_claim_operation::validate
void validate() const
Definition: operations.cpp:46
graphene::protocol::operation_validator::result_type
void result_type
Definition: operations.cpp:57
graphene::protocol::operation_get_required_auth::owner
flat_set< account_id_type > & owner
Definition: operations.cpp:67
graphene::protocol::operation_validate
void operation_validate(const operation &op)
Definition: operations.cpp:98
fee_schedule.hpp
graphene::protocol::operation_get_required_auth::ignore_custom_op_reqd_auths
bool ignore_custom_op_reqd_auths
Definition: operations.cpp:69
graphene::protocol::operation_validator::operator()
void operator()(const T &v) const
Definition: operations.cpp:59
GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION
#define GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION(type)
Definition: types.hpp:86
graphene::protocol::public_key_type
Definition: types.hpp:312
graphene::protocol::operation_get_required_auth::operation_get_required_auth
operation_get_required_auth(flat_set< account_id_type > &a, flat_set< account_id_type > &own, vector< authority > &oth, bool ignore_custom_operation_required_auths)
Definition: operations.cpp:72
graphene::protocol::operation_get_required_auth::other
vector< authority > & other
Definition: operations.cpp:68
graphene::protocol::base_operation::calculate_data_fee
static uint64_t calculate_data_fee(uint64_t bytes, uint64_t price_per_kbyte)
Definition: operations.cpp:33
operations.hpp
graphene::protocol::operation_get_required_auth::result_type
void result_type
Definition: operations.cpp:64
graphene::protocol::generic_exchange_operation_result
Definition: base.hpp:95
graphene::protocol::base_operation::get_required_owner_authorities
virtual void get_required_owner_authorities(flat_set< account_id_type > &) const
Definition: base.hpp:134
graphene::protocol::base_operation::get_required_authorities
virtual void get_required_authorities(vector< authority > &) const
Definition: base.hpp:132
graphene::protocol::operation_get_required_auth::operator()
void operator()(const T &v) const
Definition: operations.cpp:81
graphene::protocol::custom_operation::fee_payer
account_id_type fee_payer() const
Definition: custom.hpp:51
graphene::protocol::operation_get_required_authorities
void operation_get_required_authorities(const operation &op, flat_set< account_id_type > &active, flat_set< account_id_type > &owner, vector< authority > &other, bool ignore_custom_operation_required_auths)
Definition: operations.cpp:103
FC_ASSERT
#define FC_ASSERT(TEST,...)
Checks a condition and throws an assert_exception if the test is FALSE.
Definition: exception.hpp:345
graphene::protocol::base_operation::validate_parallel
fc::optional< fc::future< void > > validate_parallel(uint32_t skip) const
Definition: operations.cpp:40
graphene::protocol::base_operation::validate
virtual void validate() const
Definition: base.hpp:135
graphene::protocol::op_wrapper
necessary to support nested operations inside the proposal_create_operation
Definition: operations.hpp:153
graphene::protocol::operation_get_required_auth::operator()
void operator()(const custom_operation &op) const
Definition: operations.cpp:88
fc::static_variant::visit
visitor::result_type visit(visitor &v)
Definition: static_variant.hpp:256
fc::optional
provides stack-based nullable value similar to boost::optional
Definition: optional.hpp:20
graphene::protocol::asset
Definition: asset.hpp:31
graphene::protocol::balance_claim_operation::balance_owner_key
public_key_type balance_owner_key
Definition: balance.hpp:47
graphene::protocol::generic_operation_result
Definition: base.hpp:88
graphene::protocol::extendable_operation_result_dtl
Definition: base.hpp:102
graphene::protocol::balance_claim_operation::fee
asset fee
Definition: balance.hpp:44
graphene
Definition: api.cpp:48
graphene::protocol::operation_get_required_auth
Definition: operations.cpp:62
raw.hpp
graphene::protocol::custom_operation::get_required_active_authorities
void get_required_active_authorities(flat_set< account_id_type > &auths) const
Definition: custom.hpp:54