BitShares-Core  7.0.2
BitShares blockchain node software and command-line wallet software
balance_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 
27 namespace graphene { namespace chain {
28 
30 {
31  database& d = db();
32  balance = &op.balance_to_claim(d);
33 
34  bool is_balance_owner = (
36  pts_address(op.balance_owner_key, false) == balance->owner || // version = 56 (default)
37  pts_address(op.balance_owner_key, true) == balance->owner ); // version = 56 (default)
38  is_balance_owner = (
39  is_balance_owner ||
40  pts_address(op.balance_owner_key, false, 0) == balance->owner ||
41  pts_address(op.balance_owner_key, true, 0) == balance->owner );
42  GRAPHENE_ASSERT( is_balance_owner,
43  balance_claim_owner_mismatch,
44  "Balance owner key was specified as '${op}' but balance's actual owner is '${bal}'",
45  ("op", op.balance_owner_key)
46  ("bal", balance->owner)
47  );
48 
50 
52  {
54  balance->vesting_policy->is_withdraw_allowed(
55  { balance->balance,
56  d.head_block_time(),
57  op.total_claimed } ),
58  balance_claim_invalid_claim_amount,
59  "Attempted to claim ${c} from a vesting balance with ${a} available",
60  ("c", op.total_claimed)("a", balance->available(d.head_block_time()))
61  );
64  balance_claim_claimed_too_often,
65  "Genesis vesting balances may not be claimed more than once per day."
66  );
67  return {};
68  }
69 
71  return {};
72 }
73 
79 {
80  database& d = db();
81 
83  d.modify(*balance, [&](balance_object& b) {
84  b.vesting_policy->on_withdraw({b.balance, d.head_block_time(), op.total_claimed});
85  b.balance -= op.total_claimed;
87  });
88  else
89  d.remove(*balance);
90 
92  return {};
93 }
94 } } // namespace graphene::chain
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
pts_address.hpp
graphene::chain::balance_object::vesting_policy
optional< linear_vesting_policy > vesting_policy
Definition: balance_object.hpp:43
graphene::chain::balance_object::is_vesting_balance
bool is_vesting_balance() const
Definition: balance_object.hpp:33
graphene::protocol::balance_claim_operation::deposit_to_account
account_id_type deposit_to_account
Definition: balance.hpp:45
graphene::chain::balance_claim_evaluator::do_apply
void_result do_apply(const balance_claim_operation &op)
Definition: balance_evaluator.cpp:78
graphene::protocol::pts_address
Definition: pts_address.hpp:41
graphene::chain::balance_claim_evaluator::balance
const balance_object * balance
Definition: balance_evaluator.hpp:39
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::chain::balance_object::asset_type
asset_id_type asset_type() const
Definition: balance_object.hpp:45
graphene::chain::balance_object::balance
asset balance
Definition: balance_object.hpp:42
graphene::protocol::balance_claim_operation::total_claimed
asset total_claimed
Definition: balance.hpp:48
fc::days
microseconds days(int64_t d)
Definition: time.hpp:38
graphene::protocol::asset::asset_id
asset_id_type asset_id
Definition: asset.hpp:37
graphene::protocol::balance_claim_operation::balance_to_claim
balance_id_type balance_to_claim
Definition: balance.hpp:46
graphene::protocol::balance_claim_operation
Claim a balance in a graphene::chain::balance_object.
Definition: balance.hpp:40
graphene::chain::balance_object::available
asset available(fc::time_point_sec now) const
Definition: balance_object.hpp:35
graphene::chain::generic_evaluator::db
database & db() const
Definition: evaluator.cpp:39
graphene::chain::balance_claim_evaluator::do_evaluate
void_result do_evaluate(const balance_claim_operation &op)
Definition: balance_evaluator.cpp:29
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::balance_object::owner
address owner
Definition: balance_object.hpp:41
balance_evaluator.hpp
graphene::chain::balance_object
Definition: balance_object.hpp:30
graphene::chain::balance_object::last_claim_date
time_point_sec last_claim_date
Definition: balance_object.hpp:44
GRAPHENE_ASSERT
#define GRAPHENE_ASSERT(expr, exc_type, FORMAT,...)
Definition: exceptions.hpp:28
graphene::protocol::void_result
Definition: base.hpp:86
graphene::db::object_database::remove
void remove(const object &obj)
Definition: object_database.hpp:97
graphene::protocol::balance_claim_operation::balance_owner_key
public_key_type balance_owner_key
Definition: balance.hpp:47
graphene
Definition: api.cpp:48
graphene::db::object_database::modify
void modify(const T &obj, const Lambda &m)
Definition: object_database.hpp:99