Scorum
withdrawable_actors_impl.cpp
Go to the documentation of this file.
2 
6 
11 
12 namespace scorum {
13 namespace chain {
14 namespace database_ns {
15 
17 {
18  typedef asset result_type;
19 
20  template <typename Op> asset operator()(const Op&) const
21  {
22  FC_ASSERT(false, "Not implemented.");
23  return asset();
24  }
25 };
26 
28 {
29 public:
31  : _account_service(account_service)
32  , _dev_pool_service(dev_pool_service)
33  {
34  }
35 
36  asset operator()(const account_id_type& id) const
37  {
38  const account_object& account = _account_service.get(id);
39 
40  return account.scorumpower;
41  }
42 
44  {
45  const dev_committee_object& pool = _dev_pool_service.get();
46 
47  FC_ASSERT(id == pool.id);
48 
49  return pool.sp_balance;
50  }
51 
52 private:
53  account_service_i& _account_service;
54  dev_pool_service_i& _dev_pool_service;
55 };
56 
58 {
59  template <typename Op> void operator()(const Op&) const
60  {
61  FC_ASSERT(false, "Not implemented.");
62  }
63 };
64 
66 {
67 public:
68  decrease_sp_visitor(account_service_i& account_service, dev_pool_service_i& dev_pool_service, const asset& amount)
69  : _account_service(account_service)
70  , _dev_pool_service(dev_pool_service)
71  , _amount(amount)
72  {
73  }
74 
75  void operator()(const account_id_type& id) const
76  {
77  const account_object& from_account = _account_service.get(id);
78 
79  _account_service.decrease_scorumpower(from_account, _amount);
80  }
81 
82  void operator()(const dev_committee_id_type& id) const
83  {
84  const dev_committee_object& from_pool = _dev_pool_service.get();
85 
86  FC_ASSERT(id == from_pool.id);
87 
88  _dev_pool_service.update([&](dev_committee_object& pool) { pool.sp_balance -= _amount; });
89  }
90 
91 private:
92  account_service_i& _account_service;
93  dev_pool_service_i& _dev_pool_service;
94  const asset& _amount;
95 };
96 
98 {
99 public:
100  increase_scr_visitor(account_service_i& account_service, dev_pool_service_i& dev_pool_service, const asset& amount)
101  : _account_service(account_service)
102  , _dev_pool_service(dev_pool_service)
103  , _amount(amount)
104  {
105  }
106 
107  void operator()(const account_id_type& to) const
108  {
109  const account_object& to_account = _account_service.get(to);
110 
111  _account_service.increase_balance(to_account, _amount);
112  }
113 
114  void operator()(const dev_committee_id_type& to) const
115  {
116  const dev_committee_object& to_pool = _dev_pool_service.get();
117 
118  FC_ASSERT(to == to_pool.id);
119 
120  _dev_pool_service.update([&](dev_committee_object& pool) { pool.scr_balance += _amount; });
121  }
122 
123 private:
124  account_service_i& _account_service;
125  dev_pool_service_i& _dev_pool_service;
126  const asset& _amount;
127 };
128 
130 {
131 public:
132  increase_sp_visitor(account_service_i& account_service, dev_pool_service_i& dev_pool_service, const asset& amount)
133  : _account_service(account_service)
134  , _dev_pool_service(dev_pool_service)
135  , _amount(amount)
136  {
137  }
138 
139  void operator()(const account_id_type& id) const
140  {
141  const account_object& to_account = _account_service.get(id);
142 
143  _account_service.increase_scorumpower(to_account, _amount);
144  }
145 
146  void operator()(const dev_committee_id_type& id) const
147  {
148  const dev_committee_object& to_pool = _dev_pool_service.get();
149 
150  FC_ASSERT(id == to_pool.id);
151 
152  _dev_pool_service.update([&](dev_committee_object& pool) { pool.sp_balance += _amount; });
153  }
154 
155 private:
156  account_service_i& _account_service;
157  dev_pool_service_i& _dev_pool_service;
158  const asset& _amount;
159 };
160 
162 {
163  class update_statistic_from_account_visitor : public void_return_visitor
164  {
165  public:
166  update_statistic_from_account_visitor(account_service_i& account_service,
168  const account_id_type& from,
169  const asset& amount)
170  : _account_service(account_service)
171  , _emmiter(emmiter)
172  , _from(from)
173  , _amount(amount)
174  {
175  }
176 
177  void operator()(const account_id_type& to) const
178  {
179  const account_object& from_account = _account_service.get(_from);
180  const account_object& to_account = _account_service.get(to);
181 
182  _emmiter.push_virtual_operation(
183  acc_to_acc_vesting_withdraw_operation(from_account.name, to_account.name, _amount));
184  }
185 
186  void operator()(const dev_committee_id_type& to) const
187  {
188  const account_object& from_account = _account_service.get(_from);
189 
190  _emmiter.push_virtual_operation(acc_to_devpool_vesting_withdraw_operation(from_account.name, _amount));
191  }
192 
193  private:
194  account_service_i& _account_service;
196  const account_id_type& _from;
197  const asset& _amount;
198  };
199 
200  class update_statistic_from_dev_committee_visitor : public void_return_visitor
201  {
202  public:
203  update_statistic_from_dev_committee_visitor(account_service_i& account_service,
205  const asset& amount)
206  : _account_service(account_service)
207  , _emmiter(emmiter)
208  , _amount(amount)
209  {
210  }
211 
212  void operator()(const account_id_type& to) const
213  {
214  const account_object& to_account = _account_service.get(to);
215 
216  _emmiter.push_virtual_operation(devpool_to_acc_vesting_withdraw_operation(to_account.name, _amount));
217  }
218 
219  void operator()(const dev_committee_id_type& to) const
220  {
221  _emmiter.push_virtual_operation(devpool_to_devpool_vesting_withdraw_operation(_amount));
222  }
223 
224  private:
225  account_service_i& _account_service;
227  const asset& _amount;
228  };
229 
230 public:
233  const withdrawable_id_type& to,
234  const asset& amount)
235  : _account_service(account_service)
236  , _emmiter(emmiter)
237  , _to(to)
238  , _amount(amount)
239  {
240  }
241 
242  void operator()(const account_id_type& from) const
243  {
244  _to.visit(update_statistic_from_account_visitor(_account_service, _emmiter, from, _amount));
245  }
246 
248  {
249  _to.visit(update_statistic_from_dev_committee_visitor(_account_service, _emmiter, _amount));
250  }
251 
252 private:
253  account_service_i& _account_service;
255  const withdrawable_id_type& _to;
256  const asset& _amount;
257 };
258 
259 // withdrawable_actors_impl
260 //
261 
263  : _ctx(ctx)
264  , _account_service(ctx.services().account_service())
265  , _dev_pool_service(ctx.services().dev_pool_service())
266  , _dprops_service(ctx.services().dynamic_global_property_service())
267 {
268 }
269 
271 {
272  return from.visit(get_available_scorumpower_visitor(_account_service, _dev_pool_service));
273 }
274 
276  const withdrawable_id_type& to,
277  const asset& amount)
278 {
279  if (amount.amount > 0)
280  {
281  from.visit(update_statistic_visitor(_account_service, _ctx, to, amount));
282  }
283 }
284 
286 {
287  auto op = from.visit(
288  [&](const account_id_type& from) {
289  return protocol::operation(acc_finished_vesting_withdraw_operation(_account_service.get(from).name));
290  },
291  [&](const dev_committee_id_type& from) {
293  });
294 
295  _ctx.push_virtual_operation(op);
296 }
297 
299 {
300  FC_ASSERT(amount.symbol() == SCORUM_SYMBOL);
301  if (amount.amount > 0)
302  {
303  id.visit(increase_scr_visitor(_account_service, _dev_pool_service, amount));
304  }
305 }
306 
308 {
309  FC_ASSERT(amount.symbol() == SP_SYMBOL);
310  if (amount.amount > 0)
311  {
312  id.visit(increase_sp_visitor(_account_service, _dev_pool_service, amount));
313  }
314 }
315 
317 {
318  FC_ASSERT(amount.symbol() == SP_SYMBOL);
319  FC_ASSERT(amount.amount > 0);
320 
321  from.visit(decrease_sp_visitor(_account_service, _dev_pool_service, amount));
322 }
323 }
324 }
325 }
virtual void push_virtual_operation(const operation &op)
Definition: block_tasks.cpp:22
void operator()(const account_id_type &id) const
decrease_sp_visitor(account_service_i &account_service, dev_pool_service_i &dev_pool_service, const asset &amount)
void operator()(const dev_committee_id_type &id) const
get_available_scorumpower_visitor(account_service_i &account_service, dev_pool_service_i &dev_pool_service)
increase_scr_visitor(account_service_i &account_service, dev_pool_service_i &dev_pool_service, const asset &amount)
void operator()(const dev_committee_id_type &to) const
void operator()(const dev_committee_id_type &id) const
increase_sp_visitor(account_service_i &account_service, dev_pool_service_i &dev_pool_service, const asset &amount)
void operator()(const dev_committee_id_type &) const
update_statistic_visitor(account_service_i &account_service, database_virtual_operations_emmiter_i &emmiter, const withdrawable_id_type &to, const asset &amount)
void update_statistic(const withdrawable_id_type &from, const withdrawable_id_type &to, const asset &amount)
asset get_available_scorumpower(const withdrawable_id_type &from)
void decrease_sp(const withdrawable_id_type &id, const asset &amount)
void increase_sp(const withdrawable_id_type &id, const asset &amount)
void increase_scr(const withdrawable_id_type &id, const asset &amount)
#define SP_SYMBOL
Definition: config.hpp:104
#define SCORUM_SYMBOL
Definition: config.hpp:102
fc::static_variant< account_id_type, dev_committee_id_type > withdrawable_id_type
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
Definition: asset.cpp:15
virtual void increase_balance(const account_object &account, const asset &amount)=0
virtual void increase_scorumpower(const account_object &account, const asset &amount)=0
virtual const account_object & get(const account_id_type &) const =0
virtual void decrease_scorumpower(const account_object &account, const asset &amount)=0
virtual void update(const modifier_type &modifier)=0
virtual const object_type & get() const =0
asset_symbol_type symbol() const
Definition: asset.hpp:32
share_type amount
Definition: asset.hpp:31