Scorum
create_budget_evaluator.cpp
Go to the documentation of this file.
2 
4 
8 
12 
13 #include <boost/uuid/uuid_io.hpp>
14 
15 namespace scorum {
16 namespace chain {
17 
18 create_budget_evaluator::create_budget_evaluator(data_service_factory_i& services)
19  : evaluator_impl<data_service_factory_i, create_budget_evaluator>(services)
20  , _account_svc(services.account_service())
21  , _post_budget_svc(services.post_budget_service())
22  , _banner_budget_svc(services.banner_budget_service())
23  , _dprops_svc(services.dynamic_global_property_service())
24 {
25 }
26 
28 {
29  _account_svc.check_account_existence(op.owner);
30 
31  const auto& owner = _account_svc.get_account(op.owner);
32 
33  FC_ASSERT(owner.balance >= op.balance, "Insufficient funds.",
34  ("owner.balance", owner.balance)("balance", op.balance));
35  FC_ASSERT(_post_budget_svc.get_budgets(owner.name).size() + _banner_budget_svc.get_budgets(owner.name).size()
37  "Can't create more then ${1} budgets per owner.", ("1", SCORUM_BUDGETS_LIMIT_PER_OWNER));
38 
39  FC_ASSERT(op.start <= op.deadline, "Deadline time must be greater or equal than start time");
40  FC_ASSERT(op.start > _dprops_svc.head_block_time(), "Start time must be greater than head block time");
41 
42  switch (op.type)
43  {
44  case budget_type::post:
45  create_budget(_post_budget_svc, op, owner.name);
46  break;
47  case budget_type::banner:
48  create_budget(_banner_budget_svc, op, owner.name);
49  break;
50  }
51 }
52 
53 template <budget_type budget_type_v>
54 void create_budget_evaluator::create_budget(adv_budget_service_i<budget_type_v>& budget_svc,
57 {
58  using namespace boost::uuids;
59 
60  FC_ASSERT(!budget_svc.is_exists(op.uuid), "Budget with uuid ${1} already exists", ("1", to_string(op.uuid)));
61 
62  budget_svc.create_budget(op.uuid, owner, op.balance, op.start, op.deadline, op.json_metadata);
63 }
64 }
65 }
create_budget_evaluator(data_service_factory_i &services)
#define SCORUM_BUDGETS_LIMIT_PER_OWNER
Definition: config.hpp:147
fc::fixed_string_16 account_name_type
Definition: types.hpp:62
Definition: asset.cpp:15
virtual const account_object & get_account(const account_name_type &) const =0
virtual void check_account_existence(const account_name_type &, const optional< const char * > &context_type_name=optional< const char * >()) const =0
virtual budgets_type get_budgets() const =0
virtual bool is_exists(const uuid_type &uuid) const =0
virtual const adv_budget_object< budget_type_v > & create_budget(const uuid_type &uuid, const account_name_type &owner, const asset &balance, fc::time_point_sec start, fc::time_point_sec end, const std::string &json_metadata)=0
virtual fc::time_point_sec head_block_time() const =0