2015-06-08 15:50:35 +00:00
|
|
|
/*
|
2015-10-12 17:48:40 +00:00
|
|
|
* Copyright (c) 2015 Cryptonomex, Inc., and contributors.
|
|
|
|
|
*
|
2016-01-06 09:51:18 +00:00
|
|
|
* The MIT License
|
2015-10-12 17:48:40 +00:00
|
|
|
*
|
2016-01-06 09:51:18 +00:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
|
* furnished to do so, subject to the following conditions:
|
2015-10-12 17:48:40 +00:00
|
|
|
*
|
2016-01-06 09:51:18 +00:00
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
|
* all copies or substantial portions of the Software.
|
2015-10-12 17:02:59 +00:00
|
|
|
*
|
2016-01-06 09:51:18 +00:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
|
* THE SOFTWARE.
|
2015-06-08 15:50:35 +00:00
|
|
|
*/
|
|
|
|
|
#include <graphene/chain/database.hpp>
|
|
|
|
|
#include <graphene/chain/worker_evaluator.hpp>
|
2016-01-08 16:39:01 +00:00
|
|
|
|
2015-06-08 15:50:35 +00:00
|
|
|
#include <graphene/chain/account_object.hpp>
|
2016-01-08 16:39:01 +00:00
|
|
|
#include <graphene/chain/vesting_balance_object.hpp>
|
|
|
|
|
#include <graphene/chain/worker_object.hpp>
|
|
|
|
|
|
2015-07-23 17:09:13 +00:00
|
|
|
#include <graphene/chain/protocol/vote.hpp>
|
2015-06-08 15:50:35 +00:00
|
|
|
|
|
|
|
|
namespace graphene { namespace chain {
|
|
|
|
|
|
2015-06-23 21:33:06 +00:00
|
|
|
void_result worker_create_evaluator::do_evaluate(const worker_create_evaluator::operation_type& o)
|
2015-06-08 15:50:35 +00:00
|
|
|
{ try {
|
|
|
|
|
database& d = db();
|
|
|
|
|
|
2015-06-09 20:46:00 +00:00
|
|
|
FC_ASSERT(d.get(o.owner).is_lifetime_member());
|
2015-06-08 15:50:35 +00:00
|
|
|
FC_ASSERT(o.work_begin_date >= d.head_block_time());
|
|
|
|
|
|
2015-06-23 21:33:06 +00:00
|
|
|
return void_result();
|
|
|
|
|
} FC_CAPTURE_AND_RETHROW( (o) ) }
|
2015-06-08 15:50:35 +00:00
|
|
|
|
2015-07-08 20:39:23 +00:00
|
|
|
|
2016-01-08 16:39:01 +00:00
|
|
|
struct worker_init_visitor
|
2015-07-08 20:39:23 +00:00
|
|
|
{
|
|
|
|
|
typedef void result_type;
|
|
|
|
|
|
|
|
|
|
worker_object& worker;
|
|
|
|
|
database& db;
|
|
|
|
|
|
|
|
|
|
worker_init_visitor( worker_object& w, database& d ):worker(w),db(d){}
|
|
|
|
|
|
|
|
|
|
result_type operator()( const vesting_balance_worker_initializer& i )const
|
|
|
|
|
{
|
|
|
|
|
vesting_balance_worker_type w;
|
|
|
|
|
w.balance = db.create<vesting_balance_object>([&](vesting_balance_object& b) {
|
|
|
|
|
b.owner = worker.worker_account;
|
|
|
|
|
b.balance = asset(0);
|
|
|
|
|
|
|
|
|
|
cdd_vesting_policy policy;
|
|
|
|
|
policy.vesting_seconds = fc::days(i.pay_vesting_period_days).to_seconds();
|
|
|
|
|
policy.coin_seconds_earned = 0;
|
|
|
|
|
policy.coin_seconds_earned_last_update = db.head_block_time();
|
|
|
|
|
b.policy = policy;
|
|
|
|
|
}).id;
|
|
|
|
|
worker.worker = w;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
|
result_type operator()( const T& )const
|
|
|
|
|
{
|
|
|
|
|
// DO NOTHING FOR OTHER WORKERS
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-06-08 15:50:35 +00:00
|
|
|
object_id_type worker_create_evaluator::do_apply(const worker_create_evaluator::operation_type& o)
|
|
|
|
|
{ try {
|
|
|
|
|
database& d = db();
|
|
|
|
|
vote_id_type for_id, against_id;
|
|
|
|
|
d.modify(d.get_global_properties(), [&for_id, &against_id](global_property_object& p) {
|
2015-07-23 17:09:13 +00:00
|
|
|
for_id = get_next_vote_id(p, vote_id_type::worker);
|
|
|
|
|
against_id = get_next_vote_id(p, vote_id_type::worker);
|
2015-06-08 15:50:35 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return d.create<worker_object>([&](worker_object& w) {
|
|
|
|
|
w.worker_account = o.owner;
|
|
|
|
|
w.daily_pay = o.daily_pay;
|
|
|
|
|
w.work_begin_date = o.work_begin_date;
|
|
|
|
|
w.work_end_date = o.work_end_date;
|
2015-06-29 14:01:42 +00:00
|
|
|
w.name = o.name;
|
|
|
|
|
w.url = o.url;
|
2015-06-08 15:50:35 +00:00
|
|
|
w.vote_for = for_id;
|
|
|
|
|
w.vote_against = against_id;
|
2015-07-08 20:39:23 +00:00
|
|
|
|
2015-06-08 15:50:35 +00:00
|
|
|
w.worker.set_which(o.initializer.which());
|
2015-07-08 20:39:23 +00:00
|
|
|
o.initializer.visit( worker_init_visitor( w, d ) );
|
2015-06-08 15:50:35 +00:00
|
|
|
}).id;
|
2015-06-23 21:33:06 +00:00
|
|
|
} FC_CAPTURE_AND_RETHROW( (o) ) }
|
2015-06-08 15:50:35 +00:00
|
|
|
|
2015-07-08 20:39:23 +00:00
|
|
|
void refund_worker_type::pay_worker(share_type pay, database& db)
|
|
|
|
|
{
|
|
|
|
|
total_burned += pay;
|
2020-03-21 08:47:46 +00:00
|
|
|
db.modify(db.get(asset_id_type()).dynamic_data(db), [pay](asset_dynamic_data_object& d) {
|
2015-07-08 20:39:23 +00:00
|
|
|
d.current_supply -= pay;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void vesting_balance_worker_type::pay_worker(share_type pay, database& db)
|
|
|
|
|
{
|
|
|
|
|
db.modify(balance(db), [&](vesting_balance_object& b) {
|
|
|
|
|
b.deposit(db.head_block_time(), asset(pay));
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void burn_worker_type::pay_worker(share_type pay, database& db)
|
|
|
|
|
{
|
|
|
|
|
total_burned += pay;
|
|
|
|
|
db.adjust_balance( GRAPHENE_NULL_ACCOUNT, pay );
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-08 15:50:35 +00:00
|
|
|
} } // graphene::chain
|