BitShares-Core  7.0.2
BitShares blockchain node software and command-line wallet 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 
54 
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
graphene::chain::cdd_vesting_policy
defines vesting in terms of coin-days accrued which allows for dynamic deposit/withdraw
Definition: vesting_balance_object.hpp:89
FC_CAPTURE_AND_RETHROW
#define FC_CAPTURE_AND_RETHROW(...)
Definition: exception.hpp:479
graphene::chain::cdd_vesting_policy::coin_seconds_earned
fc::uint128_t coin_seconds_earned
Definition: vesting_balance_object.hpp:92
graphene::chain::database
tracks the blockchain state in an extensible manner
Definition: database.hpp:70
graphene::chain::database::head_block_time
time_point_sec head_block_time() const
Definition: db_getter.cpp:67
graphene::db::object_database::get
const T & get(const object_id_type &id) const
Definition: object_database.hpp:119
database.hpp
graphene::chain::refund_worker_type::pay_worker
void pay_worker(share_type pay, database &)
Definition: worker_evaluator.cpp:107
worker_evaluator.hpp
graphene::chain::worker_init_visitor
Definition: worker_evaluator.cpp:46
graphene::chain::vesting_balance_worker_type::pay_worker
void pay_worker(share_type pay, database &db)
Definition: worker_evaluator.cpp:115
graphene::db::object_database::create
const T & create(F &&constructor)
Definition: object_database.hpp:63
graphene::chain::database::adjust_balance
void adjust_balance(account_id_type account, asset delta)
Adjust a particular account's balance in a given asset by a delta.
Definition: db_balance.cpp:54
graphene::protocol::vote_id_type
An ID for some votable object.
Definition: vote.hpp:51
graphene::protocol::worker_create_operation::daily_pay
share_type daily_pay
Definition: worker.hpp:87
worker_object.hpp
graphene::chain::vesting_balance_object::deposit
void deposit(const fc::time_point_sec &now, const asset &amount)
Deposit amount into vesting balance, requiring it to vest before withdrawal.
Definition: vesting_balance_object.cpp:240
graphene::protocol::worker_create_operation::url
string url
Definition: worker.hpp:89
graphene::protocol::worker_create_operation
Create a new worker object.
Definition: worker.hpp:79
graphene::protocol::worker_create_operation::initializer
worker_initializer initializer
This should be set to the initializer appropriate for the type of worker to be created.
Definition: worker.hpp:91
graphene::chain::vesting_balance_object
Definition: vesting_balance_object.hpp:151
graphene::chain::refund_worker_type::total_burned
share_type total_burned
Record of how much this worker has burned in his lifetime.
Definition: worker_object.hpp:64
graphene::chain::burn_worker_type::pay_worker
void pay_worker(share_type pay, database &)
Definition: worker_evaluator.cpp:123
fc::days
microseconds days(int64_t d)
Definition: time.hpp:38
graphene::chain::vesting_balance_worker_type
A worker who sends his pay to a vesting balance.
Definition: worker_object.hpp:74
graphene::chain::cdd_vesting_policy::coin_seconds_earned_last_update
fc::time_point_sec coin_seconds_earned_last_update
Definition: vesting_balance_object.hpp:95
graphene::chain::asset_dynamic_data_object
tracks the asset information that changes frequently
Definition: asset_object.hpp:56
graphene::chain::database::get_core_dynamic_data
const asset_dynamic_data_object & get_core_dynamic_data() const
Definition: db_getter.cpp:42
graphene::protocol::worker_create_operation::work_end_date
time_point_sec work_end_date
Definition: worker.hpp:86
account_object.hpp
graphene::protocol::vote_id_type::worker
@ worker
Definition: vote.hpp:62
vesting_balance_object.hpp
graphene::chain::worker_create_evaluator::do_evaluate
void_result do_evaluate(const operation_type &o)
Definition: worker_evaluator.cpp:35
graphene::chain::vesting_balance_worker_type::balance
vesting_balance_id_type balance
The balance this worker pays into.
Definition: worker_object.hpp:77
graphene::chain::worker_object::worker
worker_type worker
ID of this worker's pay balance.
Definition: worker_object.hpp:119
vote.hpp
fc::microseconds::to_seconds
int64_t to_seconds() const
Definition: time.hpp:29
graphene::chain::worker_init_visitor::db
database & db
Definition: worker_evaluator.cpp:51
graphene::chain::worker_init_visitor::operator()
result_type operator()(const T &) const
Definition: worker_evaluator.cpp:73
graphene::chain::worker_init_visitor::worker_init_visitor
worker_init_visitor(worker_object &w, database &d)
Definition: worker_evaluator.cpp:53
graphene::chain::generic_evaluator::db
database & db() const
Definition: evaluator.cpp:39
FC_ASSERT
#define FC_ASSERT(TEST,...)
Checks a condition and throws an assert_exception if the test is FALSE.
Definition: exception.hpp:345
graphene::chain::worker_object
Worker object contains the details of a blockchain worker. See The Blockchain Worker System for detai...
Definition: worker_object.hpp:107
graphene::db::object_id_type
Definition: object_id.hpp:30
graphene::protocol::vesting_balance_worker_initializer
Definition: worker.hpp:56
graphene::protocol::worker_create_operation::name
string name
Definition: worker.hpp:88
fc::static_variant::which
tag_type which() const
Definition: static_variant.hpp:329
graphene::chain::worker_init_visitor::operator()
result_type operator()(const vesting_balance_worker_initializer &i) const
Definition: worker_evaluator.cpp:55
graphene::chain::burn_worker_type::total_burned
share_type total_burned
Record of how much this worker has burned in his lifetime.
Definition: worker_object.hpp:90
graphene::chain::global_property_object
Maintains global state information (committee_member list, current fees)
Definition: global_property_object.hpp:40
graphene::protocol::vesting_balance_worker_initializer::pay_vesting_period_days
uint16_t pay_vesting_period_days
Definition: worker.hpp:59
graphene::protocol::worker_create_operation::owner
account_id_type owner
Definition: worker.hpp:84
GRAPHENE_NULL_ACCOUNT
#define GRAPHENE_NULL_ACCOUNT
Represents the canonical account with NO authority (nobody can access funds in null account)
Definition: config.hpp:146
fc::static_variant::visit
visitor::result_type visit(visitor &v)
Definition: static_variant.hpp:256
graphene::chain::database::get_global_properties
const global_property_object & get_global_properties() const
Definition: db_getter.cpp:47
graphene::chain::vesting_balance_type::worker
@ worker
graphene::protocol::asset
Definition: asset.hpp:31
graphene::protocol::void_result
Definition: base.hpp:86
graphene::protocol::worker_create_operation::work_begin_date
time_point_sec work_begin_date
Definition: worker.hpp:85
graphene::chain::cdd_vesting_policy::vesting_seconds
uint32_t vesting_seconds
Definition: vesting_balance_object.hpp:91
graphene::chain::worker_create_evaluator::do_apply
object_id_type do_apply(const operation_type &o)
Definition: worker_evaluator.cpp:83
graphene::chain::worker_object::worker_account
account_id_type worker_account
ID of the account which owns this worker.
Definition: worker_object.hpp:111
graphene::chain::worker_init_visitor::worker
worker_object & worker
Definition: worker_evaluator.cpp:50
graphene
Definition: api.cpp:48
graphene::db::object_database::modify
void modify(const T &obj, const Lambda &m)
Definition: object_database.hpp:99
graphene::chain::worker_init_visitor::result_type
void result_type
Definition: worker_evaluator.cpp:48
fc::safe
Definition: safe.hpp:26