Scorum
proposal.cpp
Go to the documentation of this file.
3 
4 namespace scorum {
5 namespace chain {
6 
9 {
10 }
11 
14  const fc::time_point_sec& expiration,
15  uint64_t quorum)
16 {
17  return create([&](proposal_object& proposal) {
18  proposal.creator = creator;
19  proposal.operation = operation;
20  proposal.created = head_block_time();
21  proposal.expiration = expiration;
22  proposal.quorum_percent = quorum;
23  });
24 }
25 
27 {
28  return find_by<by_id>(proposal_id) != nullptr;
29 }
30 
32 {
33  return get_by<by_id>(proposal_id);
34 }
35 
37 {
38  update(proposal, [&](proposal_object& p) { p.voted_accounts.insert(voter); });
39 }
40 
42 {
43  return proposal.voted_accounts.size();
44 }
45 
47 {
48  return (head_block_time() > proposal.expiration) ? true : false;
49 }
50 
52 {
53  const auto& proposal_expiration_index = db_impl().get_index<proposal_object_index>().indices().get<by_expiration>();
54 
55  while (!proposal_expiration_index.empty() && is_expired(*proposal_expiration_index.begin()))
56  {
57  remove(*proposal_expiration_index.begin());
58  }
59 }
60 
62 {
63  auto& proposals = db_impl().get_index<proposal_object_index>().indices().get<by_id>();
64 
65  for (const proposal_object& proposal : proposals)
66  {
68 
69  auto it = p.voted_accounts.find(member);
70 
71  if (it != p.voted_accounts.end())
72  {
73  p.voted_accounts.erase(it);
74  }
75  });
76  }
77 }
78 
79 std::vector<proposal_object::cref_type> dbs_proposal::get_proposals()
80 {
81  std::vector<proposal_object::cref_type> ret;
82 
83  const auto& idx = db_impl().get_index<proposal_object_index>().indices().get<by_created>();
84 
85  for (auto it = idx.cbegin(); it != idx.end(); ++it)
86  {
87  ret.push_back(std::cref(*it));
88  }
89 
90  return ret;
91 }
92 
93 } // namespace scorum
94 } // namespace chain
tracks the blockchain state in an extensible manner
Definition: database.hpp:52
time_point_sec head_block_time()
Definition: dbs_base.cpp:17
dba::db_index & db_impl()
Definition: dbs_base.cpp:22
void clear_expired_proposals() override
Definition: proposal.cpp:51
proposal_refs_type get_proposals() override
Definition: proposal.cpp:79
virtual const proposal_object & create_proposal(const account_name_type &creator, const protocol::proposal_operation &operation, const fc::time_point_sec &expiration, uint64_t quorum) override
Definition: proposal.cpp:12
size_t get_votes(const proposal_object &proposal) override
Definition: proposal.cpp:41
void vote_for(const account_name_type &voter, const proposal_object &proposal) override
Definition: proposal.cpp:36
bool is_expired(const proposal_object &proposal) override
Definition: proposal.cpp:46
dbs_proposal(database &db)
Definition: proposal.cpp:7
void for_all_proposals_remove_from_voting_list(const account_name_type &member) override
Definition: proposal.cpp:61
virtual const object_type & create(const modifier_type &modifier) override
virtual void update(const modifier_type &modifier) override
virtual const object_type & get() const override
fc::shared_flat_set< account_name_type > voted_accounts
shared_multi_index_container< proposal_object, indexed_by< ordered_unique< tag< by_id >, member< proposal_object, proposal_id_type, &proposal_object::id > >, ordered_non_unique< tag< by_expiration >, member< proposal_object, fc::time_point_sec, &proposal_object::expiration > >, ordered_non_unique< tag< by_created >, member< proposal_object, fc::time_point_sec, &proposal_object::created > > > > proposal_object_index
fc::static_variant< vote_operation, comment_operation, transfer_operation, transfer_to_scorumpower_operation, withdraw_scorumpower_operation, account_create_by_committee_operation, account_create_operation, account_create_with_delegation_operation, account_update_operation, witness_update_operation, account_witness_vote_operation, account_witness_proxy_operation, delete_comment_operation, comment_options_operation, set_withdraw_scorumpower_route_to_account_operation, set_withdraw_scorumpower_route_to_dev_pool_operation, prove_authority_operation, request_account_recovery_operation, recover_account_operation, change_recovery_account_operation, escrow_approve_operation, escrow_dispute_operation, escrow_release_operation, escrow_transfer_operation, decline_voting_rights_operation, delegate_scorumpower_operation, create_budget_operation, close_budget_operation, proposal_vote_operation, proposal_create_operation, atomicswap_initiate_operation, atomicswap_redeem_operation, atomicswap_refund_operation, close_budget_by_advertising_moderator_operation, update_budget_operation, create_game_operation, cancel_game_operation, update_game_markets_operation, update_game_start_time_operation, post_game_results_operation, post_bet_operation, cancel_pending_bets_operation, delegate_sp_from_reg_pool_operation, create_nft_operation, update_nft_meta_operation, create_game_round_operation, update_game_round_result_operation, adjust_nft_experience_operation, update_nft_name_operation, author_reward_operation, comment_benefficiary_reward_operation, comment_payout_update_operation, comment_reward_operation, curation_reward_operation, hardfork_operation, producer_reward_operation, active_sp_holders_reward_operation, return_scorumpower_delegation_operation, shutdown_witness_operation, witness_miss_block_operation, expired_contract_refund_operation, acc_finished_vesting_withdraw_operation, devpool_finished_vesting_withdraw_operation, acc_to_acc_vesting_withdraw_operation, devpool_to_acc_vesting_withdraw_operation, acc_to_devpool_vesting_withdraw_operation, devpool_to_devpool_vesting_withdraw_operation, proposal_virtual_operation, budget_outgo_operation, budget_owner_income_operation, active_sp_holders_reward_legacy_operation, budget_closing_operation, bets_matched_operation, game_status_changed_operation, bet_resolved_operation, bet_cancelled_operation, bet_restored_operation, bet_updated_operation > operation
Definition: operations.hpp:112
fc::fixed_string_16 account_name_type
Definition: types.hpp:62
fc::static_variant< registration_committee_add_member_operation, registration_committee_exclude_member_operation, registration_committee_change_quorum_operation, development_committee_add_member_operation, development_committee_exclude_member_operation, development_committee_change_quorum_operation, development_committee_withdraw_vesting_operation, development_committee_transfer_operation, development_committee_empower_advertising_moderator_operation, development_committee_change_post_budgets_auction_properties_operation, development_committee_change_banner_budgets_auction_properties_operation, development_committee_empower_betting_moderator_operation, development_committee_change_betting_resolve_delay_operation > proposal_operation
signed_transaction proposal(const std::string &initiator, uint32_t lifetime_sec, C &&constructor)
Definition: wallet.cpp:2754
Definition: asset.cpp:15
fc::time_point_sec expiration
Definition: transaction.hpp:16