-
Notifications
You must be signed in to change notification settings - Fork 649
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update balance evaluator / authority checks
- move balance_claim_evalautor implementation from header - remove authority check from balance_claim evaluator, added to other_auths defined by the operation
- Loading branch information
1 parent
93aff09
commit e873d3e
Showing
8 changed files
with
77 additions
and
54 deletions.
There are no files selected for viewing
Submodule docs
updated
from d0d1fd to f3012a
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#include <graphene/chain/balance_evaluator.hpp> | ||
|
||
namespace graphene { namespace chain { | ||
|
||
void_result balance_claim_evaluator::do_evaluate(const balance_claim_operation& op) | ||
{ | ||
database& d = db(); | ||
balance = &op.balance_to_claim(d); | ||
|
||
FC_ASSERT(op.balance_owner_key == balance->owner || | ||
pts_address(op.balance_owner_key, false, 56) == balance->owner || | ||
pts_address(op.balance_owner_key, true, 56) == balance->owner || | ||
pts_address(op.balance_owner_key, false, 0) == balance->owner || | ||
pts_address(op.balance_owner_key, true, 0) == balance->owner, | ||
"balance_owner_key does not match balance's owner"); | ||
if( !(d.get_node_properties().skip_flags & (database::skip_authority_check | | ||
database::skip_transaction_signatures)) ) | ||
|
||
FC_ASSERT(op.total_claimed.asset_id == balance->asset_type()); | ||
|
||
if( balance->is_vesting_balance() ) { | ||
if( !balance->vesting_policy->is_withdraw_allowed({balance->balance, | ||
d.head_block_time(), | ||
op.total_claimed}) ) | ||
FC_THROW_EXCEPTION(invalid_claim_amount, | ||
"Attempted to claim ${c} from a vesting balance with ${a} available", | ||
("c", op.total_claimed)("a", balance->available(d.head_block_time()))); | ||
if( d.head_block_time() - balance->last_claim_date < fc::days(1) ) | ||
FC_THROW_EXCEPTION(balance_claimed_too_often, | ||
"Genesis vesting balances may not be claimed more than once per day."); | ||
return {}; | ||
} | ||
|
||
FC_ASSERT(op.total_claimed == balance->balance); | ||
return {}; | ||
} | ||
|
||
/** | ||
* @note the fee is always 0 for this particular operation because once the | ||
* balance is claimed it frees up memory and it cannot be used to spam the network | ||
*/ | ||
void_result balance_claim_evaluator::do_apply(const balance_claim_operation& op) | ||
{ | ||
database& d = db(); | ||
|
||
if( balance->is_vesting_balance() && op.total_claimed < balance->balance ) | ||
d.modify(*balance, [&](balance_object& b) { | ||
b.vesting_policy->on_withdraw({b.balance, d.head_block_time(), op.total_claimed}); | ||
b.balance -= op.total_claimed; | ||
b.last_claim_date = d.head_block_time(); | ||
}); | ||
else | ||
d.remove(*balance); | ||
|
||
d.adjust_balance(op.deposit_to_account, op.total_claimed); | ||
return {}; | ||
} | ||
} } // namespace graphene::chain |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters