BitShares-Core  4.0.0
BitShares blockchain implementation and command-line interface software
proposal_object.hpp
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 #pragma once
25 
29 
30 #include <boost/multi_index/composite_key.hpp>
31 
32 namespace graphene { namespace chain {
33  class database;
34 
40 class proposal_object : public abstract_object<proposal_object>
41 {
42  public:
43  static const uint8_t space_id = protocol_ids;
44  static const uint8_t type_id = proposal_object_type;
45 
46  time_point_sec expiration_time;
49  flat_set<account_id_type> required_active_approvals;
50  flat_set<account_id_type> available_active_approvals;
51  flat_set<account_id_type> required_owner_approvals;
52  flat_set<account_id_type> available_owner_approvals;
53  flat_set<public_key_type> available_key_approvals;
54  account_id_type proposer;
55  std::string fail_reason;
56 
57  bool is_authorized_to_execute(database& db) const;
58 };
59 
72 {
73  public:
74  virtual void object_inserted( const object& obj ) override;
75  virtual void object_removed( const object& obj ) override;
76  virtual void about_to_modify( const object& before ) override;
77  virtual void object_modified( const object& after ) override;
78 
79  map<account_id_type, set<proposal_id_type> > _account_to_proposals;
80 
81  private:
82  void remove( account_id_type a, proposal_id_type p );
83  void insert_or_remove_delta( proposal_id_type p, const flat_set<account_id_type>& before,
84  const flat_set<account_id_type>& after );
85  flat_set<account_id_type> available_active_before_modify;
86  flat_set<account_id_type> available_owner_before_modify;
87 };
88 
89 struct by_expiration{};
90 typedef boost::multi_index_container<
92  indexed_by<
93  ordered_unique< tag< by_id >, member< object, object_id_type, &object::id > >,
94  //ordered_non_unique< tag< by_expiration >, member< proposal_object, time_point_sec, &proposal_object::expiration_time > >
95  ordered_unique<tag<by_expiration>,
96  composite_key<proposal_object,
97  member<proposal_object, time_point_sec, &proposal_object::expiration_time>,
98  member< object, object_id_type, &object::id >
99  >
100  >
101  >
104 
105 } } // graphene::chain
106 
108 
110 
tracks all of the proposal objects that requrie approval of an individual account.
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 MAP_OBJECT_ID_TO_TYPE(OBJECT)
Definition: object_id.hpp:98
flat_set< account_id_type > required_owner_approvals
groups operations that should be applied atomically
Definition: transaction.hpp:68
flat_set< account_id_type > available_owner_approvals
provides stack-based nullable value similar to boost::optional
Definition: optional.hpp:20
FC_REFLECT_TYPENAME(fc::log_message)
#define GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION(type)
Definition: types.hpp:73
generic_index< proposal_object, proposal_multi_index_container > proposal_index
map< account_id_type, set< proposal_id_type > > _account_to_proposals
optional< time_point_sec > review_period_time
Use the Curiously Recurring Template Pattern to automatically add the ability to clone, serialize, and move objects polymorphically.
Definition: object.hpp:90
flat_set< account_id_type > required_active_approvals
bool is_authorized_to_execute(database &db) const
boost::multi_index_container< proposal_object, indexed_by< ordered_unique< tag< by_id >, member< object, object_id_type,&object::id > >, ordered_unique< tag< by_expiration >, composite_key< proposal_object, member< proposal_object, time_point_sec,&proposal_object::expiration_time >, member< object, object_id_type,&object::id > > > >> proposal_multi_index_container
flat_set< public_key_type > available_key_approvals
tracks the approval of a partially approved transaction