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/withdraw_permission_evaluator.hpp>
|
|
|
|
|
#include <graphene/chain/withdraw_permission_object.hpp>
|
|
|
|
|
#include <graphene/chain/account_object.hpp>
|
|
|
|
|
#include <graphene/chain/database.hpp>
|
2015-07-08 20:30:32 +00:00
|
|
|
#include <graphene/chain/exceptions.hpp>
|
2015-10-30 17:47:22 +00:00
|
|
|
#include <graphene/chain/hardfork.hpp>
|
Make is_authorized_asset a free-floating method #566
The following sed commands were used to port existing call sites to the new interface:
sed -i -e 's/\([a-zA-Z0-9_]\+\)->is_authorized_asset[(] \([a-zA-Z0-9_*]\+\), d [)]/is_authorized_asset( d, *\1, \2 )/' libraries/chain/*.cpp
sed -i -e 's/\([a-zA-Z0-9_]\+\)[.]is_authorized_asset[(] \([a-zA-Z0-9_*]\+\), d [)]/is_authorized_asset( d, \1, \2 )/' libraries/chain/*.cpp
sed -i -e 's/\([a-zA-Z0-9_]\+\)[(]db[)][.]is_authorized_asset[(]\([a-zA-Z0-9_*]\+\)[(]db[)], db[)]/is_authorized_asset( db, \1(db), \2(db) )/' tests/tests/uia_tests.cpp
sed -i -e 's/\([a-zA-Z0-9_]\+\)[.]is_authorized_asset[(]\([a-zA-Z0-9_*]\+\), db[)]/is_authorized_asset( db, \1, \2 )/' tests/tests/uia_tests.cpp
No new functionality is added by this commit, it is simply re-organizing the existing code in a different place.
2016-02-10 21:24:56 +00:00
|
|
|
#include <graphene/chain/is_authorized_asset.hpp>
|
2015-06-08 15:50:35 +00:00
|
|
|
|
|
|
|
|
namespace graphene { namespace chain {
|
|
|
|
|
|
2015-06-23 21:33:06 +00:00
|
|
|
void_result withdraw_permission_create_evaluator::do_evaluate(const operation_type& op)
|
2015-06-08 15:50:35 +00:00
|
|
|
{ try {
|
|
|
|
|
database& d = db();
|
|
|
|
|
FC_ASSERT(d.find_object(op.withdraw_from_account));
|
|
|
|
|
FC_ASSERT(d.find_object(op.authorized_account));
|
|
|
|
|
FC_ASSERT(d.find_object(op.withdrawal_limit.asset_id));
|
|
|
|
|
FC_ASSERT(op.period_start_time > d.head_block_time());
|
|
|
|
|
FC_ASSERT(op.period_start_time + op.periods_until_expiration * op.withdrawal_period_sec > d.head_block_time());
|
|
|
|
|
FC_ASSERT(op.withdrawal_period_sec >= d.get_global_properties().parameters.block_interval);
|
|
|
|
|
|
2015-06-23 21:33:06 +00:00
|
|
|
return void_result();
|
2015-06-08 15:50:35 +00:00
|
|
|
} FC_CAPTURE_AND_RETHROW( (op) ) }
|
|
|
|
|
|
|
|
|
|
object_id_type withdraw_permission_create_evaluator::do_apply(const operation_type& op)
|
|
|
|
|
{ try {
|
|
|
|
|
return db().create<withdraw_permission_object>([&op](withdraw_permission_object& p) {
|
|
|
|
|
p.withdraw_from_account = op.withdraw_from_account;
|
|
|
|
|
p.authorized_account = op.authorized_account;
|
|
|
|
|
p.withdrawal_limit = op.withdrawal_limit;
|
|
|
|
|
p.withdrawal_period_sec = op.withdrawal_period_sec;
|
2015-06-23 21:33:06 +00:00
|
|
|
p.expiration = op.period_start_time + op.periods_until_expiration * op.withdrawal_period_sec;
|
2015-06-08 15:50:35 +00:00
|
|
|
p.period_start_time = op.period_start_time;
|
|
|
|
|
}).id;
|
|
|
|
|
} FC_CAPTURE_AND_RETHROW( (op) ) }
|
|
|
|
|
|
|
|
|
|
void_result withdraw_permission_claim_evaluator::do_evaluate(const withdraw_permission_claim_evaluator::operation_type& op)
|
|
|
|
|
{ try {
|
2015-10-30 17:10:09 +00:00
|
|
|
const database& d = db();
|
2015-06-08 15:50:35 +00:00
|
|
|
|
|
|
|
|
const withdraw_permission_object& permit = op.withdraw_permission(d);
|
|
|
|
|
FC_ASSERT(permit.expiration > d.head_block_time() );
|
|
|
|
|
FC_ASSERT(permit.authorized_account == op.withdraw_to_account);
|
|
|
|
|
FC_ASSERT(permit.withdraw_from_account == op.withdraw_from_account);
|
|
|
|
|
FC_ASSERT(op.amount_to_withdraw <= permit.available_this_period( d.head_block_time() ) );
|
|
|
|
|
FC_ASSERT(d.get_balance(op.withdraw_from_account, op.amount_to_withdraw.asset_id) >= op.amount_to_withdraw);
|
|
|
|
|
|
|
|
|
|
const asset_object& _asset = op.amount_to_withdraw.asset_id(d);
|
|
|
|
|
if( _asset.is_transfer_restricted() ) FC_ASSERT( _asset.issuer == permit.authorized_account || _asset.issuer == permit.withdraw_from_account );
|
|
|
|
|
|
2016-02-11 08:12:18 +00:00
|
|
|
const account_object& from = op.withdraw_to_account(d);
|
|
|
|
|
const account_object& to = permit.authorized_account(d);
|
|
|
|
|
FC_ASSERT( is_authorized_asset( d, to, _asset ) );
|
|
|
|
|
FC_ASSERT( is_authorized_asset( d, from, _asset ) );
|
2015-06-08 15:50:35 +00:00
|
|
|
|
|
|
|
|
return void_result();
|
|
|
|
|
} FC_CAPTURE_AND_RETHROW( (op) ) }
|
|
|
|
|
|
|
|
|
|
void_result withdraw_permission_claim_evaluator::do_apply(const withdraw_permission_claim_evaluator::operation_type& op)
|
|
|
|
|
{ try {
|
|
|
|
|
database& d = db();
|
|
|
|
|
|
|
|
|
|
const withdraw_permission_object& permit = d.get(op.withdraw_permission);
|
|
|
|
|
d.modify(permit, [&](withdraw_permission_object& p) {
|
|
|
|
|
auto periods = (d.head_block_time() - p.period_start_time).to_seconds() / p.withdrawal_period_sec;
|
|
|
|
|
p.period_start_time += periods * p.withdrawal_period_sec;
|
|
|
|
|
if( periods == 0 )
|
|
|
|
|
p.claimed_this_period += op.amount_to_withdraw.amount;
|
|
|
|
|
else
|
|
|
|
|
p.claimed_this_period = op.amount_to_withdraw.amount;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
d.adjust_balance(op.withdraw_from_account, -op.amount_to_withdraw);
|
|
|
|
|
d.adjust_balance(op.withdraw_to_account, op.amount_to_withdraw);
|
|
|
|
|
|
|
|
|
|
return void_result();
|
|
|
|
|
} FC_CAPTURE_AND_RETHROW( (op) ) }
|
|
|
|
|
|
|
|
|
|
void_result withdraw_permission_update_evaluator::do_evaluate(const withdraw_permission_update_evaluator::operation_type& op)
|
|
|
|
|
{ try {
|
|
|
|
|
database& d = db();
|
|
|
|
|
|
|
|
|
|
const withdraw_permission_object& permit = op.permission_to_update(d);
|
|
|
|
|
FC_ASSERT(permit.authorized_account == op.authorized_account);
|
|
|
|
|
FC_ASSERT(permit.withdraw_from_account == op.withdraw_from_account);
|
|
|
|
|
FC_ASSERT(d.find_object(op.withdrawal_limit.asset_id));
|
|
|
|
|
FC_ASSERT(op.period_start_time >= d.head_block_time());
|
|
|
|
|
FC_ASSERT(op.period_start_time + op.periods_until_expiration * op.withdrawal_period_sec > d.head_block_time());
|
|
|
|
|
FC_ASSERT(op.withdrawal_period_sec >= d.get_global_properties().parameters.block_interval);
|
|
|
|
|
|
|
|
|
|
return void_result();
|
|
|
|
|
} FC_CAPTURE_AND_RETHROW( (op) ) }
|
|
|
|
|
|
|
|
|
|
void_result withdraw_permission_update_evaluator::do_apply(const withdraw_permission_update_evaluator::operation_type& op)
|
|
|
|
|
{ try {
|
|
|
|
|
database& d = db();
|
|
|
|
|
|
|
|
|
|
d.modify(op.permission_to_update(d), [&op](withdraw_permission_object& p) {
|
|
|
|
|
p.period_start_time = op.period_start_time;
|
|
|
|
|
p.expiration = op.period_start_time + op.periods_until_expiration * op.withdrawal_period_sec;
|
|
|
|
|
p.withdrawal_limit = op.withdrawal_limit;
|
|
|
|
|
p.withdrawal_period_sec = op.withdrawal_period_sec;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return void_result();
|
|
|
|
|
} FC_CAPTURE_AND_RETHROW( (op) ) }
|
|
|
|
|
|
|
|
|
|
void_result withdraw_permission_delete_evaluator::do_evaluate(const withdraw_permission_delete_evaluator::operation_type& op)
|
|
|
|
|
{ try {
|
|
|
|
|
database& d = db();
|
|
|
|
|
|
|
|
|
|
const withdraw_permission_object& permit = op.withdrawal_permission(d);
|
|
|
|
|
FC_ASSERT(permit.authorized_account == op.authorized_account);
|
|
|
|
|
FC_ASSERT(permit.withdraw_from_account == op.withdraw_from_account);
|
|
|
|
|
|
|
|
|
|
return void_result();
|
|
|
|
|
} FC_CAPTURE_AND_RETHROW( (op) ) }
|
|
|
|
|
|
|
|
|
|
void_result withdraw_permission_delete_evaluator::do_apply(const withdraw_permission_delete_evaluator::operation_type& op)
|
2015-06-23 21:33:06 +00:00
|
|
|
{ try {
|
2015-06-08 15:50:35 +00:00
|
|
|
db().remove(db().get(op.withdrawal_permission));
|
|
|
|
|
return void_result();
|
2015-06-23 21:33:06 +00:00
|
|
|
} FC_CAPTURE_AND_RETHROW( (op) ) }
|
2015-06-08 15:50:35 +00:00
|
|
|
|
|
|
|
|
} } // graphene::chain
|