BitShares-Core  6.1.0
BitShares blockchain implementation and command-line interface software
worker_evaluator.cpp
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  */
26 
30 
32 
33 namespace graphene { namespace chain {
34 
36 { try {
37  database& d = db();
38 
39  FC_ASSERT(d.get(o.owner).is_lifetime_member());
41 
42  return void_result();
43 } FC_CAPTURE_AND_RETHROW( (o) ) }
44 
45 
47 {
48  typedef void result_type;
49 
52 
53  worker_init_visitor( worker_object& w, database& d ):worker(w),db(d){}
54 
55  result_type operator()( const vesting_balance_worker_initializer& i )const
56  {
59  b.owner = worker.worker_account;
60  b.balance = asset(0);
61  b.balance_type = vesting_balance_type::worker;
62 
63  cdd_vesting_policy policy;
65  policy.coin_seconds_earned = 0;
67  b.policy = policy;
68  }).id;
69  worker.worker = w;
70  }
71 
72  template<typename T>
73  result_type operator()( const T& )const
74  {
75  // DO NOTHING FOR OTHER WORKERS
76  }
77 };
78 
79 
80 
81 
82 
84 { try {
85  database& d = db();
86  vote_id_type for_id, against_id;
87  d.modify(d.get_global_properties(), [&for_id, &against_id](global_property_object& p) {
88  for_id = vote_id_type(vote_id_type::worker, p.next_available_vote_id++);
89  against_id = vote_id_type(vote_id_type::worker, p.next_available_vote_id++);
90  });
91 
92  return d.create<worker_object>([&](worker_object& w) {
93  w.worker_account = o.owner;
94  w.daily_pay = o.daily_pay;
95  w.work_begin_date = o.work_begin_date;
96  w.work_end_date = o.work_end_date;
97  w.name = o.name;
98  w.url = o.url;
99  w.vote_for = for_id;
100  w.vote_against = against_id;
101 
102  w.worker.set_which(o.initializer.which());
104  }).id;
105 } FC_CAPTURE_AND_RETHROW( (o) ) }
106 
108 {
109  total_burned += pay;
111  d.current_supply -= pay;
112  });
113 }
114 
116 {
117  db.modify(balance(db), [&](vesting_balance_object& b) {
118  b.deposit(db.head_block_time(), asset(pay));
119  });
120 }
121 
122 
124 {
125  total_burned += pay;
127 }
128 
129 } } // graphene::chain
void modify(const T &obj, const Lambda &m)
void adjust_balance(account_id_type account, asset delta)
Adjust a particular account&#39;s balance in a given asset by a delta.
Definition: db_balance.cpp:54
time_point_sec head_block_time() const
Definition: db_getter.cpp:67
void pay_worker(share_type pay, database &)
tracks the blockchain state in an extensible manner
Definition: database.hpp:70
result_type operator()(const vesting_balance_worker_initializer &i) const
int64_t to_seconds() const
Definition: time.hpp:29
Definition: api.cpp:48
void pay_worker(share_type pay, database &db)
void deposit(const fc::time_point_sec &now, const asset &amount)
Deposit amount into vesting balance, requiring it to vest before withdrawal.
visitor::result_type visit(visitor &v)
tag_type which() const
microseconds days(int64_t d)
Definition: time.hpp:38
const T & get(const object_id_type &id) const
vesting_balance_id_type balance
The balance this worker pays into.
result_type operator()(const T &) const
void pay_worker(share_type pay, database &)
worker_type worker
ID of this worker&#39;s pay balance.
#define FC_CAPTURE_AND_RETHROW(...)
Definition: exception.hpp:479
worker_initializer initializer
This should be set to the initializer appropriate for the type of worker to be created.
Definition: worker.hpp:91
#define FC_ASSERT(TEST,...)
Checks a condition and throws an assert_exception if the test is FALSE.
Definition: exception.hpp:345
tracks the asset information that changes frequentlyBecause the asset_object is very large it doesn&#39;t...
#define GRAPHENE_NULL_ACCOUNT
Represents the canonical account with NO authority (nobody can access funds in null account) ...
Definition: config.hpp:146
const asset_dynamic_data_object & get_core_dynamic_data() const
Definition: db_getter.cpp:42
An ID for some votable object.
Definition: vote.hpp:51
object_id_type do_apply(const operation_type &o)
worker_init_visitor(worker_object &w, database &d)
account_id_type worker_account
ID of the account which owns this worker.
Worker object contains the details of a blockchain worker. See The Blockchain Worker System for detai...
void_result do_evaluate(const operation_type &o)
defines vesting in terms of coin-days accrued which allows for dynamic deposit/withdraw ...
Maintains global state information (committee_member list, current fees)This is an implementation det...
share_type current_supply
The number of shares currently in existence.
Create a new worker object.
Definition: worker.hpp:79
const T & create(F &&constructor)
A worker who sends his pay to a vesting balance.
const global_property_object & get_global_properties() const
Definition: db_getter.cpp:47