Scorum
registration_pool.cpp
Go to the documentation of this file.
3 
5 
6 namespace scorum {
7 namespace chain {
8 
10  : base_service_type(db)
11 {
12 }
13 
15  const asset& maximum_bonus,
16  const schedule_items_type& schedule_items)
17 {
18  FC_ASSERT(supply > asset(0, SCORUM_SYMBOL), "Registration supply amount must be more than zerro.");
19  FC_ASSERT(maximum_bonus > asset(0, SCORUM_SYMBOL), "Registration maximum bonus amount must be more than zerro.");
20  FC_ASSERT(!schedule_items.empty(), "Registration schedule must have at least one item.");
21 
22  // check schedule
23  for (const auto& value : schedule_items)
24  {
25  const auto& stage = value.first;
26  const schedule_item_type& item = value.second;
27  FC_ASSERT(item.users > 0, "Invalid schedule value (users in thousands) for stage ${1}.", ("1", stage));
28  FC_ASSERT(item.bonus_percent >= 0 && item.bonus_percent <= 100,
29  "Invalid schedule value (percent) for stage ${1}.", ("1", stage));
30  }
31 
32  // Check existence here to allow unit tests check input data even if object exists in DB
33  // This method uses get(id == 0). Look get_pool.
34  FC_ASSERT(!is_exists(), "Can't create more than one pool.");
35 
36  // create pool
37  return create([&](registration_pool_object& pool) {
38  pool.balance = supply;
39  pool.maximum_bonus = maximum_bonus;
40  pool.schedule_items.reserve(schedule_items.size());
41  for (const auto& value : schedule_items)
42  {
43  pool.schedule_items.push_back(value.second);
44  }
45  });
46 }
47 
49 {
50  const registration_pool_object& this_pool = get();
51 
52  db_impl().modify(this_pool, [&](registration_pool_object& pool) { pool.balance -= amount; });
53 }
54 
56 {
58 }
59 } // namespace chain
60 } // namespace scorum
tracks the blockchain state in an extensible manner
Definition: database.hpp:52
dba::db_index & db_impl()
Definition: dbs_base.cpp:22
void decrease_balance(const asset &amount) override
const registration_pool_object & create_pool(const asset &supply, const asset &maximum_bonus, const schedule_items_type &schedule_items) override
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_vector< schedule_item > schedule_items
#define SCORUM_SYMBOL
Definition: config.hpp:102
Definition: asset.cpp:15
std::map< uint8_t, schedule_item_type > schedule_items_type