BitShares-Core  4.0.0
BitShares blockchain implementation and command-line interface software
proposal_object.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-2018 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  */
25 #include <graphene/chain/hardfork.hpp>
28 #include <graphene/chain/hardfork.hpp>
29 
31 
32 namespace graphene { namespace chain {
33 
35 {
36  transaction_evaluation_state dry_run_eval( &db );
37 
38  try {
39  bool allow_non_immediate_owner = ( db.head_block_time() >= HARDFORK_CORE_584_TIME );
42  [&db]( account_id_type id ){ return &id( db ).active; },
43  [&db]( account_id_type id ){ return &id( db ).owner; },
44  [&db]( account_id_type id, const operation& op, rejected_predicate_map* rejects ){
45  return db.get_viable_custom_authorities(id, op, rejects); },
46  allow_non_immediate_owner,
47  MUST_IGNORE_CUSTOM_OP_REQD_AUTHS( db.head_block_time() ),
49  true, /* allow committee */
52  }
53  catch ( const fc::exception& e )
54  {
55  return false;
56  }
57  return true;
58 }
59 
61 {
62  assert( dynamic_cast<const proposal_object*>(&obj) );
63  const proposal_object& p = static_cast<const proposal_object&>(obj);
64 
65  for( const auto& a : p.required_active_approvals )
66  _account_to_proposals[a].insert( p.id );
67  for( const auto& a : p.required_owner_approvals )
68  _account_to_proposals[a].insert( p.id );
69  for( const auto& a : p.available_active_approvals )
70  _account_to_proposals[a].insert( p.id );
71  for( const auto& a : p.available_owner_approvals )
72  _account_to_proposals[a].insert( p.id );
73 }
74 
75 void required_approval_index::remove( account_id_type a, proposal_id_type p )
76 {
77  auto itr = _account_to_proposals.find(a);
78  if( itr != _account_to_proposals.end() )
79  {
80  itr->second.erase( p );
81  if( itr->second.empty() )
82  _account_to_proposals.erase( itr->first );
83  }
84 }
85 
86 void required_approval_index::object_removed( const object& obj )
87 {
88  assert( dynamic_cast<const proposal_object*>(&obj) );
89  const proposal_object& p = static_cast<const proposal_object&>(obj);
90 
91  for( const auto& a : p.required_active_approvals )
92  remove( a, p.id );
93  for( const auto& a : p.required_owner_approvals )
94  remove( a, p.id );
95  for( const auto& a : p.available_active_approvals )
96  remove( a, p.id );
97  for( const auto& a : p.available_owner_approvals )
98  remove( a, p.id );
99 }
100 
101 void required_approval_index::insert_or_remove_delta( proposal_id_type p,
102  const flat_set<account_id_type>& before,
103  const flat_set<account_id_type>& after )
104 {
105  auto b = before.begin();
106  auto a = after.begin();
107  while( b != before.end() || a != after.end() )
108  {
109  if( a == after.end() || (b != before.end() && *b < *a) )
110  {
111  remove( *b, p );
112  ++b;
113  }
114  else if( b == before.end() || (a != after.end() && *a < *b) )
115  {
116  _account_to_proposals[*a].insert( p );
117  ++a;
118  }
119  else // *a == *b
120  {
121  ++a;
122  ++b;
123  }
124  }
125 }
126 
127 void required_approval_index::about_to_modify( const object& before )
128 {
129  const proposal_object& p = static_cast<const proposal_object&>(before);
130  available_active_before_modify = p.available_active_approvals;
131  available_owner_before_modify = p.available_owner_approvals;
132 }
133 
134 void required_approval_index::object_modified( const object& after )
135 {
136  const proposal_object& p = static_cast<const proposal_object&>(after);
137  insert_or_remove_delta( p.id, available_active_before_modify, p.available_active_approvals );
138  insert_or_remove_delta( p.id, available_owner_before_modify, p.available_owner_approvals );
139 }
140 
141 } } // graphene::chain
142 
147 
map< custom_authority_id_type, rejected_predicate > rejected_predicate_map
Definition: transaction.hpp:31
vector< operation > operations
Definition: transaction.hpp:89
virtual void object_removed(const object &obj) override
flat_set< account_id_type > available_active_approvals
tracks the blockchain state in an extensible manner
Definition: database.hpp:70
Definition: api.cpp:56
#define FC_REFLECT_DERIVED_NO_TYPENAME(TYPE, INHERITS, MEMBERS)
Definition: reflect.hpp:356
Used to generate a useful error report when an exception is thrown.At each level in the stack where t...
Definition: exception.hpp:56
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 >
flat_set< account_id_type > required_owner_approvals
flat_set< account_id_type > available_owner_approvals
const global_property_object & get_global_properties() const
Definition: db_getter.cpp:44
virtual void object_modified(const object &after) override
object_id_type id
Definition: object.hpp:73
void verify_authority(const vector< operation > &ops, const flat_set< public_key_type > &sigs, const std::function< const authority *(account_id_type)> &get_active, const std::function< const authority *(account_id_type)> &get_owner, const custom_authority_lookup &get_custom, bool allow_non_immediate_owner, bool ignore_custom_operation_required_auths, uint32_t max_recursion=GRAPHENE_MAX_SIG_CHECK_DEPTH, bool allow_committee=false, const flat_set< account_id_type > &active_aprovals=flat_set< account_id_type >(), const flat_set< account_id_type > &owner_approvals=flat_set< account_id_type >())
time_point_sec head_block_time() const
Definition: db_getter.cpp:64
virtual void about_to_modify(const object &before) override
#define GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION(type)
Definition: types.hpp:74
optional< time_point_sec > review_period_time
flat_set< account_id_type > required_active_approvals
bool is_authorized_to_execute(database &db) const
flat_set< public_key_type > available_key_approvals
base for all database objects
Definition: object.hpp:62
virtual void object_inserted(const object &obj) override
tracks the approval of a partially approved transaction