BitShares-Core  7.0.2
BitShares blockchain node software and command-line wallet 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  const proposal_id_type proposal_id = p.get_id();
65 
66  for( const auto& a : p.required_active_approvals )
67  _account_to_proposals[a].insert( proposal_id );
68  for( const auto& a : p.required_owner_approvals )
69  _account_to_proposals[a].insert( proposal_id );
70  for( const auto& a : p.available_active_approvals )
71  _account_to_proposals[a].insert( proposal_id );
72  for( const auto& a : p.available_owner_approvals )
73  _account_to_proposals[a].insert( proposal_id );
74 }
75 
76 void required_approval_index::remove( account_id_type a, proposal_id_type p )
77 {
78  auto itr = _account_to_proposals.find(a);
79  if( itr != _account_to_proposals.end() )
80  {
81  itr->second.erase( p );
82  if( itr->second.empty() )
83  _account_to_proposals.erase( itr->first );
84  }
85 }
86 
87 void required_approval_index::object_removed( const object& obj )
88 {
89  assert( dynamic_cast<const proposal_object*>(&obj) );
90  const proposal_object& p = static_cast<const proposal_object&>(obj);
91  const proposal_id_type proposal_id = p.get_id();
92 
93  for( const auto& a : p.required_active_approvals )
94  remove( a, proposal_id );
95  for( const auto& a : p.required_owner_approvals )
96  remove( a, proposal_id );
97  for( const auto& a : p.available_active_approvals )
98  remove( a, proposal_id );
99  for( const auto& a : p.available_owner_approvals )
100  remove( a, proposal_id );
101 }
102 
103 void required_approval_index::insert_or_remove_delta( proposal_id_type p,
104  const flat_set<account_id_type>& before,
105  const flat_set<account_id_type>& after )
106 {
107  auto b = before.begin();
108  auto a = after.begin();
109  while( b != before.end() || a != after.end() )
110  {
111  if( a == after.end() || (b != before.end() && *b < *a) )
112  {
113  remove( *b, p );
114  ++b;
115  }
116  else if( b == before.end() || (a != after.end() && *a < *b) )
117  {
118  _account_to_proposals[*a].insert( p );
119  ++a;
120  }
121  else // *a == *b
122  {
123  ++a;
124  ++b;
125  }
126  }
127 }
128 
129 void required_approval_index::about_to_modify( const object& before )
130 {
131  const proposal_object& p = static_cast<const proposal_object&>(before);
132  available_active_before_modify = p.available_active_approvals;
133  available_owner_before_modify = p.available_owner_approvals;
134 }
135 
136 void required_approval_index::object_modified( const object& after )
137 {
138  const proposal_object& p = static_cast<const proposal_object&>(after);
139  const proposal_id_type proposal_id = p.get_id();
140  insert_or_remove_delta( proposal_id, available_active_before_modify, p.available_active_approvals );
141  insert_or_remove_delta( proposal_id, available_owner_before_modify, p.available_owner_approvals );
142 }
143 
144 } } // graphene::chain
145 
147  (expiration_time)(review_period_time)(proposed_transaction)(required_active_approvals)
148  (available_active_approvals)(required_owner_approvals)(available_owner_approvals)
149  (available_key_approvals)(proposer)(fail_reason) )
150 
graphene::protocol::transaction::operations
vector< operation > operations
Definition: transaction.hpp:89
graphene::chain::database
tracks the blockchain state in an extensible manner
Definition: database.hpp:70
graphene::chain::proposal_object::available_owner_approvals
flat_set< account_id_type > available_owner_approvals
Definition: proposal_object.hpp:49
graphene::protocol::rejected_predicate_map
map< custom_authority_id_type, rejected_predicate > rejected_predicate_map
Definition: transaction.hpp:31
fc::exception
Used to generate a useful error report when an exception is thrown.
Definition: exception.hpp:56
graphene::chain::database::head_block_time
time_point_sec head_block_time() const
Definition: db_getter.cpp:67
graphene::chain::required_approval_index::about_to_modify
virtual void about_to_modify(const object &before) override
Definition: proposal_object.cpp:129
database.hpp
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::chain::global_property_object::parameters
chain_parameters parameters
Definition: global_property_object.hpp:44
graphene::chain::transaction_evaluation_state
Definition: transaction_evaluation_state.hpp:37
proposal_object.hpp
GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION
#define GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION(type)
Definition: types.hpp:86
graphene::chain::proposal_object::proposed_transaction
transaction proposed_transaction
Definition: proposal_object.hpp:45
graphene::protocol::verify_authority
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_approvals=flat_set< account_id_type >(), const flat_set< account_id_type > &owner_approvals=flat_set< account_id_type >())
Definition: transaction.cpp:269
graphene::chain::proposal_object::available_key_approvals
flat_set< public_key_type > available_key_approvals
Definition: proposal_object.hpp:50
graphene::chain::proposal_object::is_authorized_to_execute
bool is_authorized_to_execute(database &db) const
Definition: proposal_object.cpp:34
FC_REFLECT_DERIVED_NO_TYPENAME
#define FC_REFLECT_DERIVED_NO_TYPENAME(TYPE, INHERITS, MEMBERS)
Definition: reflect.hpp:357
graphene::protocol::chain_parameters::max_authority_depth
uint8_t max_authority_depth
Definition: chain_parameters.hpp:80
graphene::chain::required_approval_index::object_inserted
virtual void object_inserted(const object &obj) override
Definition: proposal_object.cpp:60
graphene::chain::required_approval_index::object_removed
virtual void object_removed(const object &obj) override
Definition: proposal_object.cpp:87
graphene::chain::required_approval_index::object_modified
virtual void object_modified(const object &after) override
Definition: proposal_object.cpp:136
graphene::chain::proposal_object::required_active_approvals
flat_set< account_id_type > required_active_approvals
Definition: proposal_object.hpp:46
transaction_evaluation_state.hpp
graphene::chain::proposal_object::required_owner_approvals
flat_set< account_id_type > required_owner_approvals
Definition: proposal_object.hpp:48
restriction_predicate.hpp
graphene::db::abstract_object::get_id
object_id< SpaceID, TypeID > get_id() const
Definition: object.hpp:113
graphene::chain::database::get_global_properties
const global_property_object & get_global_properties() const
Definition: db_getter.cpp:47
graphene::chain::proposal_object::available_active_approvals
flat_set< account_id_type > available_active_approvals
Definition: proposal_object.hpp:47
graphene::chain::proposal_object
tracks the approval of a partially approved transaction
Definition: proposal_object.hpp:40
graphene::chain::required_approval_index::_account_to_proposals
map< account_id_type, set< proposal_id_type > > _account_to_proposals
Definition: proposal_object.hpp:76
graphene
Definition: api.cpp:48
graphene::db::object
base for all database objects
Definition: object.hpp:61